#include<stdio.h>
#include<stdlib.h>
struct treenode{
    int data;
    struct treeNode *left, *right;
};

struct treeNode* newNode(int val){
    struct treeNode* node=(struct treeNode*)malloc(sizeof(struct treeNode));
    node->data=val;
    node->left=node->right=NULL;
    return node;
}
int main(){
    int N;
    scanf("%d", &N);
    
    if(n<=0){
        printf("Invalid input");
        return 0;
        
        if(N==0){
            int x;
            scanf("%d", &x);
            printf("%d", x);
            return 0;
        }
        struct treeNode* nodes[200];
        
        for(int i=0;i<N;i++){
            int val;
            scanf("%d", &val);
            nodes[i]=newNode(val);
        }
        for(int i=0;i<N;i++){
        int left=2*i + 1;
        int right=2*i + 2;
        
        if(left<N)
        nodes[i]->left=nodes[left];
        if(right<N)
        nodes[i]->right=nodes[right];
    }
    int x;
    scanf("%d", &x);
    
    struct treeNode* newnode=newNode(x);
    nodes[N]=newnode;
    
    int parent =(n-1)/2;
    if(nodes[parent]->left=NULL)
    nodes[parent]->left=newnode;
    else
    nodes[parent]->right=newnode;
    
    for(int i=0;i<N;i++){
        printf("%d ",nodes[i]->data);
    }
    return 0;
        
    }