from math import * from copy import * inf = 10 ** 18 def f(x, y): if gcd(x, y) != 1: return 0 v = (x - 1) * (y - 1) if v >= inf: return -1 return v N = int(input()) A = list(map(int, input().split())) if N == 2: print(f(A[0], A[1])) print(1, 2) elif N == 3: v = inf T = [(1, 2), (1, 2)], [(1, 3), (1, 2)] ans = [] for tt in T: D = deepcopy(A) for t in tt: temp = f(D[t[0] - 1], D[t[1] - 1]) D.pop(t[1] - 1) D.pop(t[0] - 1) if temp == -1: break D.append(temp) else: if D[0] < v: ans = tt v = D[0] print(v) for a, b in ans: print(a, b) else: def f1(A , ans=[]): ind1, ind2 = -1, -1 N = len(A) for i in range(N): if ind1 == -1: if A[i]%2 == 0: ind1 = i + 1 else: if A[i]%2 == 0: ind2 = i + 1 if ind2 != -1: print(0) for a, b in ans: print(a, b) print(ind1, ind2) for i in range(N - 1, 1, -1): print(1, i) exit() def f2(A): ind1, ind2 = -1, -1 N = len(A) for i in range(N): if ind1 == -1: if A[i]%2 == 1: ind1 = i + 1 else: if A[i]%2 == 1: ind2 = i + 1 v = (A.pop(ind2 - 1) - 1) * (A.pop(ind1 - 1) - 1) A.append(v) return (ind1, ind2), A t, A = f2(A) ans = [t] f1(A, ans) t, A = f2(A) ans.append(t) f1(A, ans)