#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } long long f(long long x, long long y) { if (gcd(x, y) == 1) { return (x - 1) * (y - 1); } return 0; } int main() { fast_io(); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } if (n == 2) { cout << f(a[0], a[1]) << endl; cout << "1 2" << endl; return 0; } if (n == 3) { vector ff{f(a[0], f(a[1], a[2])), f(a[1], f(a[0], a[2])), f(a[2], f(a[0], a[1]))}; int idx = min_element(ff.begin(), ff.end()) - ff.begin(); cout << ff[idx] << endl; if (idx == 0) { cout << "2 3" << endl; } else if (idx == 1) { cout << "1 3" << endl; } else { cout << "1 2" << endl; } cout << "1 2" << endl; return 0; } cout << 0 << endl; for (int i = 1; i < n; i++) { cout << "1 2" << endl; } }