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