#include <iostream>
#include <queue>
using namespace std;

//二叉排序树二
struct TreeNode{
    int  data;
    TreeNode *leftchild;
    TreeNode *rightchild;
    TreeNode(int x):data(x),leftchild(NULL),rightchild(NULL){}

};

void visit(TreeNode *t){
    cout<<t->data<<" ";
    //printf("%c ",t->data);
}

void PreOrder(TreeNode *root){
    if(root==NULL)return;
    visit(root);
    PreOrder(root->leftchild);
    PreOrder(root->rightchild);
}

void InOrder(TreeNode *root){
    if(root==NULL)return;
    InOrder(root->leftchild);
    visit(root);
    InOrder(root->rightchild);
    return;
}

void PostOrder(TreeNode *root){
    if(root==NULL)return;
    PostOrder(root->leftchild);
    PostOrder(root->rightchild);
    visit(root);
    return;
}


TreeNode* Insert(TreeNode *root,int x){
    if(root==NULL){
        root=new TreeNode(x);
    }
    if(x==root->data);
    else if (x<root->data)root->leftchild=Insert(root->leftchild,x);
    //else if(x>root->data) root->rightchild=Insert(root->rightchild,x);
    else root->rightchild=Insert(root->rightchild,x);
    return root;
}

int main(){
    int n;
    while(cin>>n){
        TreeNode *root=NULL;
        while(n--){
            int x;
            cin>>x;
            root=Insert(root,x);
        }
        PreOrder(root);
        printf("\n");
        InOrder(root);
        printf("\n");
        PostOrder(root);
        printf("\n");
    }
    return 0;
}