from math import gcd n = int(input()) a = list(map(int,input().split())) def f(x,y): return 0 if gcd(x,y)>1 else x*y-x-y+1 if n==2: print(f(a[0],a[1])); print(1,2) elif n==3: p,q,r = f(f(a[0],a[1]),a[2]),f(f(a[1],a[2]),a[0]),f(f(a[2],a[0]),a[1]) if q>=p<=r: print(p); print(1,2); print(1,2) elif q<=r: print(q); print(2.3); print(1,2) else: print(r); print(3,1); print(1,2) else: print(0); j = [[],[],[]] for i,v in enumerate(a): j[v%3].append(i) if len(j[0])==0: print(1,2); print(1,2) elif len(j[0])>=2: print(j[0][0]+1,j[0][1]+1); print(1,n-1) elif len(j[2])>=2: print(j[2][0]+1,j[2][1]+1); print(j[0][0]-(j[0][0]>j[2][0])-(j[0][0]>j[2][1])+1,n-1) else: print(j[0][0]+1,j[1][0]+1); print(1,2) for i in range(n-2,1,-1): print(1,i)