#include<stdio.h>
#include<stdlib.h>
typedef struct treenode{
    int data;
    struct treenode*left;
    struct treenode*right;
}node;
node*create(int num){
    node*newnode=(node*)malloc(sizeof(node));
    newnode->data=num;
    newnode->left=newnode->right=NULL;
    return newnode;
}
node*inserBST(node*root,int num){
    if(root==NULL){
        return create(num);
    }
    if(num==root->data){
        return root;
    }
    if(num<root->data){
        root->left=insertBST(root->left,num);
    }
    else{
        root->right=insertBST(root->right,num);
    }
    return root;
}

void postorder(node*root){
    if(root!=NULL){
        postorder(root->left);
        postorder(root->right);
        printf("%d ",root->data);
    }
}
int main(){
    int size;
    node*root=NULL;
    scanf("%d",&size);
    if(size<=0){
        printf("Invalid input");
        return 0;
    }
    int num;
    for(int i=0;i<size;i++){
        scanf("%d",&num);
        if(num<=0){
            printf("Invalid input");
            return 0;    
         }
         root=insertBST(root,num);
}
postorder(root);
return 0;
}