class Node: def __init__(self, x): self.x = x self.prev = None self.next = None class LinkedList: def __init__(self): self.front = Node(None) self.back = self.front pass def append(self, x): node = Node(x) node.prev = self.back self.back.next = node self.back = node return node def appendleft(self, x): front = self.front node = Node(x) next = front.next if next is None: node.prev = front front.next = node else: next.prev = node node.next = next node.prev = front front.next = node self.front = node return node def remove(self, node: Node): prev = node.prev next = node.next assert prev is not None prev.next = next if next is not None: next.prev = prev N = int(input()) P = list(map(lambda x: int(x)-1, input().split())) ll = LinkedList() d = {} for p in P: node = ll.append(p) d[p] = node used = set() ans = [] for i in range(N): if i in used: continue node = d[i] next = node.next if next is None: continue ans.append(node.x + 1) ans.append(next.x + 1) used.add(node.x) used.add(next.x) ll.remove(node) ll.remove(next) print(*ans)