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