#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int data;
    struct node *left;
    struct node *right;
}Node;
Node *root=NULL;
Node *create(int val){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->data=val;
    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,val);
     }
     else{
         root->right=insertBST(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;
    }
    Node *root=NULL;
    for(int i=0;i<n;i++){
        int time;
        scanf("%d",&time);
        if(time<5){
            printf("Invalid input");
            return 0;
        }
         root=insertBST(root,time);
    }
postorder(root);
return 0;
}