import sys from math import gcd from itertools import permutations 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: ans = 0 ops = [(a[0], a[1]), (a[2], a[3]), (f(a[0], a[1]), f(a[2], a[3]))] for i in range(4, n): ops.append((0, a[i])) print(ans) for x, y in ops: print(x, y)