#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 (sizeof(Node));
    newNode->data = num;
    newNode->left = NULL;
    newNode->right = NULL;
    return newNode;
}

Node* insert(Node *root,int num){
    if(root == NULL){
        return create(num);
    }
    else if(num < root->data){
        root->left = insert(root->left, num);
    }
    else if(num > root->data){
        root->right = insert(root->right, num);
    }
    else{
        return root;
    }
}

void preorder(Node *root){
    if(root != NULL){
        printf("%d",root->data);
        preorder(root->left);
        preorder(root->right);
    }
}

void inorder(){
    if(root != NULL){
        inorder(root->left);
        printf("%d",root->data);
        inorder(root->right);
    }
}

void postorder(){
    if(root != NULL){
        postorder(root->left);
        postorder(root->right);
        printf("%d",root->data);
    }
}



int main(){
    int n;
    scanf("%d",&n);
    for(itr=0;itr<n;itr++){
        scanf("%d",&num);
        root = insert(root, num);
    }
    preorder();
    printf("\n");
    inorder();
    printf("\n");
    postorder();
}