ll f(ll x,ll y){return GCD(x,y)==1?(x-1)*(y-1):0;}{ll@N,@A[N],m=1d18,k,t;if(N<3){wtLn(f(*A,A[1]),"1 2");}else if(N<4){rep(i,N){t=f(A[i],f(A[(i+1)%3],A[(i+2)%3]));if(m>t)m=t,k=i;}wt(m);wt((k+1)%3+1,(k+2)%3+1);wt(1,2);}else{wt(0);rep(2)wt(1,2);RREP(i,N-3)wt(i+1,i+2);}}