// editor1
#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}Node;
Node *create(int num){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=num;
    newnode->left=newnode->right=NULL;
    return newnode;
}
Node *insert(Node *root, int num){
    if(root==NULL){
        return create(num);
    }
    if(num<root->data){
        root->left=insert(root->left,num);
    }
    else{
        root->right=insert(root->right,num);
    }
    return root;
}
void levelOrder(Node *root){
    if(root==NULL){
        return;
    }
    Node *queue[100];
    int front=0,rear=0;
    queue[rear++]=root;
    while(front<rear){
        Node *current=queue[front++];
        printf("%d ",current->num);
        if(current->left) queue[rear++]=current->left;
        if(current->right) queue[rear++]=current->right;
    }
}
int main(){
    int n,num;
    Node *root=NULL;
    for(int i=0;i<n;i++){
        scanf("%d",&num);
        root=insert(root,num);
    }
    levelOrder(root);
    return 0;
}