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