#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left,*right;
}Node;
Node *root=NULL;
typedef struct tree{
    int data;
    Node *arr[20];
}Node1;
Node1*q;
int f=0,r=-1;
void en(Node *root){
    q->arr[f++];
}
Node *de(){
    return q->arr[f++];
}
void create(int num){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=num;
    newnode->left=NULL;
    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);
    if(num>root->data)
    root->right=insert(root->right,num);
    return root;
}

void level(Node *root){
    q=(Node1*)malloc(sizeof(Node1));
    en(root);
    while(f<=r){
        Node *temp=de();
        printf("%d ",temp->data);
        if(temp->left!=NULL)
        en(temp->left);
        if(temp->right!=NULL)
        en(temp->right);
    }
}
int main(){
    int n,i,num;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    for(i=0;i<n;i++){
        scanf("%d",&num);
        root=insert(root,num);
    }
    level(root);
    return 0;
}
    }
}