#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
struct node{
int v,s,f,ch[2];
}a[maxn];
int root=1;
void out(int rt){
if(rt){out(a[rt].ch[0]); printf("%d ",a[rt].v); out(a[rt].ch[1]);}
}
void rotate(int x,int op){
int y=a[x].f, z=a[y].f, B=a[x].ch[op];
a[x].ch[op]=y; a[y].f=x;
a[y].ch[!op]=B; a[B].f=y;
if(a[z].ch[0]==y)a[z].ch[0]=x;
else a[z].ch[1]=x;
a[x].f=z;
}
void splay(int x){
while(a[x].f){
if(!a[a[x].f].f){
rotate(x,x==a[a[x].f].ch[0]);
}else{
int y=a[x].f, z=a[y].f;
int op=y==a[z].ch[0];
if(a[y].ch[op] != x){
rotate(y,op); rotate(x,op);
}else{
rotate(x,!op); rotate(x,op);
}
}
}
root=x;
}
void insert(int rt,int x){
int p=a[x].v>a[rt].v;
if(!a[rt].ch[p]){
a[rt].ch[p]=x; a[x].f=rt; splay(x);
}else insert(a[rt].ch[p],x);
}
int main(){
int n,x;
cin>>n; cin>>a[1].v;
for(int i=2;i<=n;i++){
scanf("%d",&a[i].v);
insert(root,i);
}
out(root);
return 0;
}