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