import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ###################################################################### from sortedcontainers import SortedSet, SortedList, SortedDict n = ni() p = [x-1 for x in na()] invp = [0]*n for i in range(n): invp[p[i]] = i s = SortedSet(list(range(n))) removed = [0] * n removed[p[-1]] = 1 last = n-1 t = 0 ans = [] for i in range(n//2): while removed[t]: t += 1 removed[t] = 1 ans.append(t+1) s.remove(invp[t]) x = s.bisect_left(invp[t]) y = p[s[x]] ans.append(y+1) removed[y] = 1 s.remove(invp[y]) if invp[y] == last and i < n//2-1: last = s[-1] removed[p[last]] = 1 print(*ans)