#include<stdio.h>
#include<stdlib.h>

typedef struct Tree{
    int data;
    struct Tree *right,left;
    
}tree;

tree *root=NULL;
tree *branch;

void create(int num){
    branch=(tree*)malloc(1 * sizeof(tree));
    branch->data=num;
    branch->left=NULL;
    branch->right=NULL;
    return branch;
}

tree* insert(tree* root,int num){
    if(root->data==NULL){
        return create(num);
    }
    else if(root->data>num){
        root->left=insert(root->left,num);
    }
    else{
        root->right=insert(root->right,num);
    }
}

void preorder(tree* root){
    if(root!=NULL){
        printf("%d",root->data);
        preorder(root->left);
        preorder(root->right);
    }
}
void inorder(tree* root){
    if(root!=NULL){
        inorder(root->left);
        printf("%d",root->data);
        inorder(root->right);
    }
}
void postorder(tree* root){
    if(root!=NULL){
        postorder(root->left);
        postorder(root->right);
        printf("%d",root->data);
    }
}

int main(){
    int size;
    int num;
    int ind;
    scanf("%d",&size);
    for(ind=0;ind<size;ind++){
        scanf("%d",&num);
        create(num);
    }
    preorder(root);
    inorder(root);
    postorder(root);
    return 0;
}