// editor2
#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;
}
Node *insert(Node *root,int val){
    if(root==NULL){
        return create(val);
    }
    Node *queue[200];
    int front=0,rear=0;
    queue[rear++]=root;
    while(front<rear){
        Node *temp=queue[front++];
        if(temp->left==NULL){
            temp->left=create(val);
            return root;
        }
        else{
            queue[rear++]=temp->left;
        }
        if(temp->right==NULL){
            temp->right=create(val);
            return root;
        }
        else{
            queue[rear++]=temp->right;
        }
    }
    reti
}
void print(Node *root){
    Node *queue[200];
    int front=0,rear=0;
    if(root==NULL)
    return;
    queue[rear++]=root;
    while(front<rear){
        Node *temp=queue[front++];
        printf("%d ",temp->data);
        if(temp->left)
        queue[rear++]=temp->left;
        if(temp->right)
        queue[rear++]=temp->right;
    }
}
int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        root=insert(root,x);
    }
     int y;
        scanf("%d",&y);
        root=insert(root,y);
        print(root);
        return 0;
    }