#include<stdio.h>
#include<stdlib.h>

typedef struct node{
    int data;
    struct node *left, *right;
}Node;

typedef struct Qnode{
    Node* treeNode;
    struct node* next;
}Qnode;

Node* root=NULL;
Node *head=NULL;
void enqueue(Node *treeNode){
    Qnode* newNode = (Qnode*)malloc(1*sizeof(Qnode));
    newNode->data = treeNode;
    newNode->next = NULL;
    if(head==NULL){
        head = newNode;
        tail = newNode;
    }
    else{
        tail->next = newNode;
        tail = node;
    }
}

Node *temp;
Node* dequeue(){
    if(head==NULL){
        printf("Empty");
    }
    temp = head;
    Node* treeNode = temp->treeNode;
    head = head->next;
    free(temp);
    return treeNode;
}

Node* create(int num){
    Node *newNode = (Node*)malloc(1*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);
    }
    else if(num > root->data){
        root->right = insert(root->right,num);
    }
}

void levelOrder(Node *root){
    if(root==NULL){
        return root;
    }
    enqueue(root);
    while(head !=NULL){
        Node* current = dequeue();
        printf("%d ",current->data);
        
        if(current->left != NULL){
            enqueue(current->left);
        }
         if(current->right != NULL){
            enqueue(current->right);
        }
    }
}

int main(){
    int size,i,num;
    scanf("%d",&size);
    if(size<=0){
        printf("Invalid input");
        return 0;
    }
    for(i=1;i<=size;i++){
        scanf("%d",&num);
        root = insert(root,num);
    }
    levelOrder(root);
    return 0;
}