#include<stdio.h>
#include<stdlib.h>

typedef struct node{
    char data;
    struct node *left,*right;
}node;

node *root=NULL;

node *create(int val){
    node *n=(node*)malloc(sizeof(node));
    n->data=val;
    n->left=NULL;
    n->right=NULL;
    
    return n;
}

node *insert(node *root,int val){
    if(root==NULL){
        return create(val);
    }
    if(root->left==NULL)
       root->left=insert(root->left,val);
    else
       root->right=insert(root->right,val);
       
     return root;
}

void inorder(node *root){
    if(root!=NULL){
    postorder(root->left);
    printf("%d ",root->data);
    postorder(root->right);
    }
}
void postorder(node *root){
    if(root!=NULL){
    postorder(root->left);
    printf("%d ",root->data);
    postorder(root->right);
    }
}
void preorder(node *root){
    if(root!=NULL){
    printf("%d ",root->data);
    postorder(root->left);
    postorder(root->right);
    }
}

int main(){
    int n, val;
    scanf("%d",&n);

    
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0 ; i<n ;i++){
        scanf("%d",&val);
        root=insert(root ,val);
    }
    inorder(root);
    postorder(root);
    preorder(root);
    
    return 0;
    
}