// editor1

#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}node;
node *root=NULL;
node *create(int num){
    node*newnode=(node*)malloc(sizeof(node));
    newnode->data=num;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
node*insertBST(node*root,int t){
    if(root==NULL){
        return create(t);
    }
    if(t<root->data){
        root->left=insertBST(root->left,t);
    }
    else{
        root->right=insertBST(root->right,t);
    }
    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 *curr=queue[front++];
        printf("%d",curr->data);
        if(curr->left){
            queue[rear++]=curr->left;
        }
    if(curr->right){
        queue[rear++]=curr->right;
    }
    }
    }
    int main(){
        int size;
        scanf("%d",&size);
        if(size<=0){
            printf("Invalid input");
            return 0;
        }
        node*root=NULL;
        for(int i=0;i<size;i++){
            int t;
            scanf("%d",&t);
            root=insertBST(root,t);
        }
        levelorder(root);
    }