#include <iostream>
#include <cstdio>
using namespace std;
struct node
{
    int val;
    node *left, *right;
    node(int v):val(v),left(NULL),right(NULL){}
};

void insert(node *&root, int x)
{
    if (root == NULL)
    {
        root = new node(x);
        return;
    }
    if (root->val == x)
    {
        return;
    }
    if (x < root->val)
    {
        insert(root->left, x);
    }
    else
    {
        insert(root->right, x);
    }
}
void preOrder(node *root)
{
    if (root == NULL)
    {
        return;
    }
    printf("%d ", root->val);
    preOrder(root->left);
    preOrder(root->right);
}
void inOrder(node *root)
{
    if (root == NULL)
    {
        return;
    }
    inOrder(root->left);
    printf("%d ", root->val);
    inOrder(root->right);
}
void postOrder(node *root)
{
    if (root == NULL)
    {
        return;
    }
    postOrder(root->left);
    postOrder(root->right);
    printf("%d ", root->val);
}
int main()
{
    int n;
    while (cin >> n)
    {
        node *root = NULL;
        while (n--)
        {
            int x;
            cin >> x;
            insert(root, x);
        }
        preOrder(root);
        printf("\n");
        inOrder(root);
        printf("\n");
        postOrder(root);
        printf("\n");
    }
}