// #include <asm-generic/errno.h>
// #include <cstddef>
// #include <iostream>
// #include "algorithm"
// #include "map"
// using namespace std;
// const int N = 110;
// int a[N];
// typedef struct BTNode {
// int data;
// struct BTNode* lchild;
// struct BTNode* rchild;
// } BTNode, *BTree;
// int n;
// map <int, int > repeat;
// void Insert(BTree& T, int x) {
// if (T == NULL) {
// T = (BTree) malloc (sizeof(BTNode));
// T->data = x;
// T->lchild = NULL;
// T->rchild = NULL;
// return;
// }
// if (x == T->data) ;
// else if (x < T->data) {
// Insert(T->lchild, x);
// } else {
// Insert(T->rchild, x);
// }
// }
// void PreOrder(BTree T) {
// if (T == NULL) return;
// cout << T->data <<' ';
// PreOrder(T->lchild);
// PreOrder(T->rchild);
// }
// void inOrder(BTree T) {
// if (T == NULL) return;
// inOrder(T->lchild);
// cout << T->data <<' ';
// inOrder(T->rchild);
// }
// void postOrder(BTree T) {
// if (T == NULL) return;
// postOrder(T->lchild);
// postOrder(T->rchild);
// cout << T->data <<' ';
// }
// int main() {
// cin >> n;
// BTree T = NULL;
// for (int i = 0; i < n; i++) {
// int x;
// cin >> x;
// Insert(T, x);
// }
// PreOrder(T);
// cout << endl;
// inOrder(T);
// cout << endl;
// postOrder(T);
// cout << endl;
// }
#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;
}