#include<stdio.h>
#include<stdlib.h>

struct Node
{
    int val;
    struct Node *left, *right;
};
struct Node* newnode(int v)
{
    struct Node* n = malloc(sizeof(struct Node));
     n->val = v;
     n->left = n->right =NULL;
     return n;
}
struct Node* insert(struct node* root, int v)
{
    if(!root)return newnode(v);
    if(v < root->val) root->left = insert(root->left, v);
    else root->right = insert(root->rght, v);
    return root;
}
int mai()
{
    int n, x;
    if(scanf("%d", &n) != 1 || n <= 0)
    {
        printf("Invalid input");
        return 0;
    }
    struct node* root = NULL;
    for( int i = 0; i < n;i++)
    {
        if(scanf("%d", &x) != 1 || x <= 0)
        {
            printf("Invalid input");.
            return 0;
        }
        root = insert(root, x);
    }
    struct node* q[100];
    int front = 0, rear = 0;
    q[rear++] = root;
    while(front < rear)
    {
        struct node* cur = q[front++];
        printf("%d ", cur ->val);
        if(cur -> left) q[rear++] = cur -> right;
    }
    return 0;
}

}
}