// editor1
#include<stdio.h>
#include<stdlib.h>
struct typedef node{
    int data;
    struct node *left;
    struct node *right;
}nd;
nd *root=NULL;
nd *create(int num){
    nd *newnode=(nd*)malloc(nd));
    newnode->data=val;
    newnode->left=NULL;
    newnode->right=NULL;
    return newnode;
}
nd *buildTree(int arr[],int n,int i){
    if(i>=n || a[i]==0){
        return NULL;
    }
    nd *root=create(a[i]);
    root->left=buildTree(a[i],n,2*i+1);
    root->right=buildTree(a[i],n,2*i+2);
    return root;
}
void preorder(nd *root){
    if(root==NULL){
        return;
    }
    printf("%d ",root->data);
    preorder(root->left);
    preorder(root->right);
}
void postorder(nd *root){
     if(root==NULL){
        return;
    }
   
    preorder(root->left);
    preorder(root->right);
     printf("%d ",root->data);
}
void inorder(nd *root){
     if(root==NULL){
        return;
    }
   
    preorder(root->left);
    printf("%d ",root->data);
    preorder(root->right);
}
int main(){
    int n,
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    nd *buildTree(a,n,0);
    preorder(nd *root);
    printf("\n");
    inorder(nd *root);
    printf("\n");
    postorder(nd *root);
    printf("\n");
    retur
}