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