#include <stdio.h>
#include <stdlib.h>

typedef struct TreeNode{
    int data;
    struct TreeNode *left;
    struct TreeNode *right;
}Node;

Node *root=NULL;

Node *create(int num){
    Node *newnode=(Node*)malloc(sizeof(Node));
    
    newnode->data=num;
    newnode->left=newnode->right=NULL;
    
    return newnode;
}


Node *insertBST(Node *root,int num){
    if(root==NULL){
        return create(num);
    }
    if(num<root->data){
        root->left=insertBST(root->left, num);
    }
    else{
        root->right=insertBST(root->right, num);
    }
    return root;
}


void level(Node* root){
    if(root==NULL){
        return;
    }
    Node *queue[100] ;
    int front=rear=0;
    queue[rear++]=root;
    
    while(front<rear){
        Node* curr=queue[front++];
        printf("%d", curr->data );
        if(curr->left){
            queue[front++]=curr->left;
        }
        if(curr->right){
            queue[rear]=curr->right;
        }
    }
}

int main(){
    int size, num;
    scanf("%d", &size);
    if(size<0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0; i<size; i++){
        scanf("%d", &num);
        root=insertBST(root,num);
    }
    
    level(root);
}