#include <bits/stdc++.h>
using namespace std;
#define sz(x) static_cast<int>((x).size())
#define pb push_back
namespace BST {
struct Node {
int value;
int left, right;
Node() : left(-1), right(-1) { }
Node(int value) : value(value), left(-1), right(-1) { }
};
vector<Node> m;
void init() {
m.clear();
}
int rec(int ind, int value) {
if( ind == -1 ) {
m.pb(Node(value));
return sz(m)-1;
}
if( value < m[ind].value )
m[ind].left = rec(m[ind].left, value);
else
m[ind].right = rec(m[ind].right, value);
return ind;
}
void push(int value) {
if( m.empty() ) {
m.pb(Node(value));
} else {
rec(0,value);
}
}
void print(int ind) {
if( ind != -1 ) {
print(m[ind].left);
cout << m[ind].value << " ";
print(m[ind].right);
}
}
void print() {
print(0); cout << "\n";
}
}
int main() {
int n;
while( cin >> n ) {
BST::init();
while( n-- ) {
int t; cin >> t; BST::push(t);
}
BST::print();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIHN6KHgpIHN0YXRpY19jYXN0PGludD4oKHgpLnNpemUoKSkKI2RlZmluZSBwYiBwdXNoX2JhY2sKCm5hbWVzcGFjZSBCU1QgewoKICBzdHJ1Y3QgTm9kZSB7CiAgICBpbnQgdmFsdWU7CiAgICBpbnQgbGVmdCwgcmlnaHQ7CiAgICBOb2RlKCkgOiBsZWZ0KC0xKSwgcmlnaHQoLTEpIHsgfQogICAgTm9kZShpbnQgdmFsdWUpIDogdmFsdWUodmFsdWUpLCBsZWZ0KC0xKSwgcmlnaHQoLTEpIHsgfQogIH07CgogIHZlY3RvcjxOb2RlPiBtOwoKICB2b2lkIGluaXQoKSB7CiAgICBtLmNsZWFyKCk7CiAgfQoKICBpbnQgcmVjKGludCBpbmQsIGludCB2YWx1ZSkgewogICAgaWYoIGluZCA9PSAtMSApIHsKICAgICAgbS5wYihOb2RlKHZhbHVlKSk7CiAgICAgIHJldHVybiBzeihtKS0xOwogICAgfQogICAgaWYoIHZhbHVlIDwgbVtpbmRdLnZhbHVlICkKICAgICAgbVtpbmRdLmxlZnQgPSByZWMobVtpbmRdLmxlZnQsIHZhbHVlKTsKICAgIGVsc2UKICAgICAgbVtpbmRdLnJpZ2h0ID0gcmVjKG1baW5kXS5yaWdodCwgdmFsdWUpOwogICAgcmV0dXJuIGluZDsKICB9CgogIHZvaWQgcHVzaChpbnQgdmFsdWUpIHsKICAgIGlmKCBtLmVtcHR5KCkgKSB7CiAgICAgIG0ucGIoTm9kZSh2YWx1ZSkpOwogICAgfSBlbHNlIHsKICAgICAgcmVjKDAsdmFsdWUpOwogICAgfQogIH0KCiAgdm9pZCBwcmludChpbnQgaW5kKSB7CiAgICBpZiggaW5kICE9IC0xICkgewogICAgICBwcmludChtW2luZF0ubGVmdCk7CiAgICAgIGNvdXQgPDwgbVtpbmRdLnZhbHVlIDw8ICIgIjsKICAgICAgcHJpbnQobVtpbmRdLnJpZ2h0KTsgICAgICAgICAKICAgIH0KICB9CgogIHZvaWQgcHJpbnQoKSB7CiAgICBwcmludCgwKTsgY291dCA8PCAiXG4iOwogIH0KCn0KCmludCBtYWluKCkgewoKICBpbnQgbjsKICB3aGlsZSggY2luID4+IG4gKSB7CiAgICBCU1Q6OmluaXQoKTsKICAgIHdoaWxlKCBuLS0gKSB7CiAgICAgIGludCB0OyBjaW4gPj4gdDsgQlNUOjpwdXNoKHQpOwogICAgfQogICAgQlNUOjpwcmludCgpOwogIH0gICAgCgogIHJldHVybiAwOwp9