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