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