#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}Node;
Node *root=NULL;
Node *create(int val){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=val;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
Nod *insert(Node *root,int val){
    if(root==NULL)
        return create(val);
    if(val < root->data)
        root->left=insert(root->left,val);
    else
        root->right=insert(root->right,val);
    return root;
}
void levelorder(Node *root){
    int queue[100];
    int front=0,rear=0;
    queue[++rear]=root;
    while(fornt < 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 n;
    scanf("%d ",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    int arr[100];
    for(int i=0;i<n;i++){
        scanf("%d ",&arr[i]);
        insert(root,arr);
    }
    
    levelorder(root);
    return 0;
}