#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));
    if(newNode == NULL){
        printf("Memory is not allgoated");
        return 0;
    }
    
    newNode->data = num;
    newNode->left = NULL;
    newNode->right = NULL;
    return newNode;
}

Node* insert(Node *root, int num){
    if(root == NULL)
        return create(num);
    if(num < root->data)
        root->left = insert(root->left, num);
    else if(num > root->data)
        root->right = insert(root->right, num);
    return root;
}

void freeList(){
    Node *current = head;
    while(curent != NULL){
        Node *temp = current;
        current = current->next;
        free(temp);
    }
}

void inOrder(Node *root){
    if(root != NULL){
        inOrder(root->left);
        printf("%d ",root->data);
        inOrder(root->right);
    }
}

void postOrder(Node *root){
    if(root != NULL){
        postOrder(root->left);
        postOrder(root->right);
        printf("%d ",root->data);
    }
}

void preOrder(Node *root){
    if(root != NULL){
        printf("%d ",root->data);
        preOrder(root->left);
        preOrder(root->right);
    }
}

int main(){
    int size,num,itr;
    scanf("%d",&size);
    for(itr=0;itr<size;itr++){
        scanf("%d",&num);
        root = insert(root,num);
    }
    inOrder(root);
    printf("\n");
    preOrder(root);
    printf("\n");
    postOrder(root);
    freeList();
}