#include <bits/stdc++.h>
using namespace std;

typedef struct BiTNode {
    int data;
    struct BiTNode* lchild, *rchild;
} BiTNode, *BiTree;

void Create(BiTree& T, int n) {
    if (T == NULL) {
        T = (BiTNode*)malloc(sizeof(BiTNode));
        T->data = n;
        T->lchild = T->rchild = NULL;
    } else if (T->data == n)
        return;
    else if (T->data < n)
        Create(T->rchild, n);
    else
        Create(T->lchild, n);
}

void inorder(BiTree T) {
    if (T == NULL)
        return;
    inorder(T->lchild);
    cout << T->data << " ";
    inorder(T->rchild);
}
void preorder(BiTree T) {
    if (T == NULL)
        return;
    cout << T->data << " ";
    preorder(T->lchild);
    preorder(T->rchild);
}
void postorder(BiTree T) {
    if (T == NULL)
        return;
    postorder(T->lchild);
    postorder(T->rchild);
    cout << T->data << " ";
}

int main() {
    BiTree T;
    int n, data;
    while (cin >> n) {
        T = NULL;
        for (int i = 0; i < n; i++) {
            cin >> data;
            Create(T, data);
        }
        preorder(T);
        cout << endl;
        inorder(T);
        cout << endl;
        postorder(T);
        cout << endl;
    }



}