#include<bits/stdc++.h> #define MAX_N 50 usingnamespace std; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n, rt, l[MAX_N+5], r[MAX_N+5]; int f[MAX_N+5]; stack <int> sta; voidfind(){ int u = rt; while (~r[u]) u = l[u]; if (~l[u] && l[l[u]] == r[l[u]]) u = l[u]; sta.push(u); if (u == rt) rt = l[rt]; if (~f[u]) l[f[u]] = l[u], f[l[u]] = f[u]; for (int v = f[u]; ~v; v = f[v]) swap(l[v], r[v]); } intmain(){ read(n), f[0] = -1; memset(l, -1, sizeof l), memset(r, -1, sizeof r); for (int i = 1, d; i <= n; i++) read(d), (d < 100 ? l[d] = i : r[d-100] = i), f[i] = d < 100 ? d : d-100; for (int i = 0; i <= n; i++) find(); while (!sta.empty()) printf("%d ", sta.top()), sta.pop(); return0; }