/*1310. Right-Heavy Tree*/
#include <stdlib.h>
#include <stdio.h>
struct Node{
int data;
Node* left;
Node* right;
Node(int d){
data = d;
left = NULL;
right = NULL;
}
};
Node *root;
inline void insert(Node *&tempRoot, const int &data){
if(tempRoot == NULL){
tempRoot = new Node(data);
}
else if( data > tempRoot->data)
{
insert(tempRoot->right,data);
}
else
{
insert(tempRoot->left,data);
}
}
inline void input( const int & new_data)
{
return insert(root,new_data);
}
inline void preOrder(Node *&temp){
if(temp !=NULL){
printf(" %d", temp->data);
preOrder(temp->left);
preOrder(temp->right);
}
}
inline void inOrder(Node *&temp){
if(temp !=NULL){
inOrder(temp->left);
printf(" %d", temp->data);
inOrder(temp->right);
}
}
inline void postOrder(Node *&temp){
if(temp !=NULL){
postOrder(temp->left);
postOrder(temp->right);
printf(" %d", temp->data);
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt","w", stdout);
bool ok = false;
int n;
while(scanf("%d",&n) != EOF){
if(ok) {
//cout << endl;
printf("\n");
}
ok = true;
int data;
root = NULL;
for(int i=1; i<=n; i++)
{
//cin >> data;
scanf("%d", &data);
//insert(root,data);
input(data);
}
printf("Inorder:");
inOrder(root);
printf("\n");
printf("Preorder:");
preOrder(root);
printf("\n");
printf("Postorder:");
postOrder(root);
printf("\n");
}
// system("pause");
return 0;
}