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 = [(1, 2)] elif(n == 3): while(len(a) > 1): lis1 = [0] * 2 lis2 = [0] * 2 b = sorted(a)[:2] for i in range(2): for j, x in enumerate(a, 1): if(x != b[i]): continue lis1[i] = j lis2[i] = x break for x in lis2: a.remove(x) a.append(f(*lis2)) ops.append(tuple(lis1)) ans = a[0] else: ans = 0 ops = [(1, 2), (1, 2), (n - 3, n - 2)] for i in range(n - 3, 1, -1): ops.append((1, i)) print(ans) for x, y in ops: print(x, y)