// editor4

#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
    int data;
    struct Node *left,*right;
}node;
node* createNode(int val){
    if(val==0) return NULL;
    node* newnode=(node*)malloc(sizeof(node));
    newnode->data=val;
    newnode->left=newnode->right=NULL;
    return newnode;
}

node* insert(int arr[],int val){
    if(root==NULL) return createNode(val);
    if(val<root->data){
        root->left=insert(root->left,val);
    }
    else if(val>root->data){
        root->right=insert(root->right,val);
    }
    return root;
}
void postOrder(node* root){
    if(root==NULL) return ;
    postOrder(root->left);
    postOrder(root->right);
    printf("%d ",root->data);
}

int main(){
    int n;
    scanf("%d",&n);
    if(n<0){
        printf("Invalid input");
        return 0;
    }
    int arr[n];
    node* root=NULL;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        root=insert(root,arr[i]);
    }
    
    postOrder(root);
    return 0;
}