n = int(input()) p = [x-1 for x in list(map(int, input().split()))] invp = [-1]*n for i in range(n): invp[p[i]] = i next = [-1] * n prev = [-1] * n for i in range(n): next[i] = (i+1)%n prev[i] = (i-1)%n def remove(x): prev[next[x]] = prev[x] next[prev[x]] = next[x] removed = [0] * n removed[p[-1]] = 1 last = n-1 ans = [] x = 0 for i in range(n//2): while removed[x]: x += 1 ans.append(x+1) y = p[next[invp[x]]] ans.append(y+1) remove(invp[x]) remove(invp[y]) removed[x] = 1 removed[y] = 1 if invp[y] == last and i < n//2-1: while removed[p[last]]: last -= 1 removed[p[last]] = 1 print(*ans)