1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 using namespace std;
7 #define Maxn 110
8
9 int a[Maxn];
10
11 struct node
12 {
13 int x,lc,rc,f;
14 }t[2*Maxn];
15
16 int op[Maxn],rt;
17
18 int ffind()
19 {
20 int x=rt,nw;
21 while(t[x].rc) x=t[x].lc;
22 if(t[x].lc!=0&&t[t[x].lc].lc==0&&t[x].lc>x) nw=t[x].lc;
23 else nw=x;
24
25 if(nw==rt) rt=t[nw].lc,t[nw].f=0;
26 else
27 {
28 t[t[nw].f].lc=t[nw].lc;
29 t[t[nw].lc].f=t[nw].f;
30 x=t[nw].f;
31 while(1)
32 {
33 swap(t[x].lc,t[x].rc);
34 if(x==rt) break;
35 x=t[x].f;
36 }
37 }
38 return nw;
39 }
40
41 int main()
42 {
43 int n;
44 scanf("%d",&n);
45 op[0]=0;
46 for(int i=0;i<n;i++) t[i].lc=t[i].rc=0;
47 t[0].f=0;
48 for(int i=1;i<=n;i++)
49 {
50 int x;
51 scanf("%d",&x);
52 if(x>=100) t[x-100].rc=i,t[i].f=x-100;
53 else t[x].lc=i,t[i].f=x;
54 }
55 rt=0;
56 for(int i=0;i<=n;i++)
57 {
58 op[i]=ffind();
59 }
60 for(int i=n;i>=0;i--) printf("%d ",op[i]);
61 return 0;
62 }