# random import sys, random from math import gcd from itertools import permutations from collections import deque input = sys.stdin.readline def f(x, y): if(gcd(x, y) == 1): return (x - 1) * (y - 1) return 0 n = int(input()) a = list(map(int, input().split())) ans = 10 ** 18 ops = [] if(n == 2): ans = f(a[0], a[1]) ops = [(a[0], a[1])] elif(n == 3): for p in permutations(a): x = f(p[0], p[1]); y = f(x, p[2]) if(ans >= y): ans = y ops = [(p[0], p[1]), (x, p[2])] x = f(p[1], p[2]); y = f(x, p[0]) if(ans >= y): ans = y ops = [(p[1], p[2]), (x, p[0])] else: que = deque(a) for i in range(n - 1): if(i % 10000 == 0): random.shuffle(que) x, y = que.popleft(), que.popleft() que.append(f(x, y)) ops.append((x, y)) ans = que.popleft() print(ans) for x, y in ops: print(x, y)