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