#include <cstdio> #include <iostream> using namespace std; struct TreeNode{ int data; TreeNode* left; TreeNode* right; TreeNode(int d):data(d),left(NULL),right(NULL){} }; void Insert(TreeNode*T, int d){ if(d>T->data){ if(T->right==NULL){ printf("%d\n",T->data); T->right=new TreeNode(d); return; }else{ Insert(T->right,d); } }else{ if(T->left==NULL){ printf("%d\n",T->data); T->left=new TreeNode(d); return; }else{ Insert(T->left,d); } } return; } int main(){ int sample; while(scanf("%d",&sample)!=EOF){ int d; scanf("%d",&d); printf("%d\n",-1); TreeNode* T=new TreeNode(d); for(int i=1;i<sample;i++){ scanf("%d",&d); Insert(T,d); } } return 0; }