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