class Node: def __init__(self, val): self.val = val self.prev = None self.next = None class LinkedList: def __init__(self): self.front = None self.back = None self.size = 0 # a の後ろに b をつなぐ def _join(self, a: Node, b: Node): a.next = b b.prev = a def append(self, val) -> Node: node = Node(val) if self.front is None: self.front = self.back = node else: self._join(self.back, node) self.back = node self.size += 1 return node def appendleft(self, val) -> Node: node = Node(val) if self.front is None: self.front = self.back = node else: self._join(node, self.front) self.front = node self.size += 1 return node def remove(self, node: Node): assert self.size > 0 if self.size == 1: self.front = self.back = None elif node is self.front: self.front = self.front.next elif node is self.back: self.back = self.back.prev else: prev = node.prev next = node.next prev.next = next next.prev = prev self.size -= 1 N = int(input()) P = list(map(lambda x: int(x)-1, input().split())) ll = LinkedList() p2node = {} for p in P: p2node[p] = ll.append(p) used = set() ans = [] for i in range(N): if i in used: continue node = p2node[i] next = node.next if next is None: continue # 2 つの要素が連蔵していない ans.append(node.val + 1) ans.append(next.val + 1) ll.remove(node) ll.remove(next) used.add(node.val) used.add(next.val) print(*ans)