#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}node;
node *createnode(int data){
    if(data==0){
        return NULL;
        
    }
    node* newnode=(node*)malloc(sizeof(node));
    newnode->data=data;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
node* buildtree(int arr[],int n,int i){
    if(i>=n||arr[i]==0){
        return NULL;
       
    }
     node* root=createnode(arr[i]);
     root->left=buildtree(arr,n,2 * i + 1);
     root->right=buildtree(arr,n,2 * i + 2);
     return root;
    
}
void inorder(node* root){
    if(root==NULL){
        return NULL;
    }
    inorder(root->left);
    printf("%d ",root->data);
    inorder(root->right);
}
void postorder(node* root){
    if(root==NULL){
        return NULL;
    }
    
    postorder(root->left);
    
    postorder(root->right);
    printf("%d ",root->data);
}
int main(){
    int n;
    scanf("%d",&n);
    printf("%d",n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    
    int arr[n];
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        
    }
    for(int i=0;i<n;i++){
        
        printf("%d",arr[i]);
        
    }
    node* root=buildtree(arr,n,0);
    preorder(root);
    printf("\n");
    inorder(root)
    printf("\n");
    postorder(root);
    return 0;
    
    
    
    
    
    
    
    
    
}