#include using namespace std; int main(){ int N; cin >> N; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } auto f = [&](long long x, long long y){ if (gcd(x, y) > 1){ return (long long) 0; } else { return (x - 1) * (y - 1); } }; if (N >= 4){ cout << 0 << endl; cout << 1 << ' ' << 2 << endl; cout << 1 << ' ' << 2 << endl; cout << N - 3 << ' ' << N - 2 << endl; for (int i = N - 3; i >= 2; i--){ cout << i - 1 << ' ' << i << endl; } } else if (N == 2){ cout << f(A[0], A[1]) << endl; cout << 1 << ' ' << 2 << endl; } else { long long a = f(f(A[0], A[1]), A[2]); long long b = f(f(A[1], A[2]), A[0]); long long c = f(f(A[2], A[0]), A[1]); cout << min({a, b, c}) << endl; if (a <= b && b <= c){ cout << 1 << ' ' << 2 << endl; cout << 1 << ' ' << 2 << endl; } else if (b <= c){ cout << 2 << ' ' << 3 << endl; cout << 1 << ' ' << 2 << endl; } else { cout << 1 << ' ' << 3 << endl; cout << 1 << ' ' << 2 << endl; } } }