#include using namespace std; using ll = long long; ll f(ll x, ll y) { return (gcd(x, y) == 1) ? (x - 1) * (y - 1) : 0; } int main(){ int n; cin >> n; vector a(n); for(auto& x : a){ cin >> x; } ll ans = 0; vector > ops(n - 1, pair({})); if(n == 2){ ans = f(a[0], a[1]); ops = { {1, 2} }; } else if(n == 3){ ans = f(f(a[0], a[1]), a[2]); ops = { {1, 2}, {1, 2} }; ll t = f(f(a[0], a[2]), a[1]); if(t < ans){ ans = t; ops = { {1, 3}, {1, 2} }; } t = f(f(a[1], a[2]), a[0]); if(t < ans){ ans = t; ops = { {2, 3}, {1, 2} }; } } else{ ans = 0; ops[0] = {1, 2}; ops[1] = {1, 2}; ops[2] = {n - 3, n - 2}; for(int i = n - 3; i > 1; --i){ ops[n - i] = {1, i}; } } cout << ans << endl; for(auto&[x, y] : ops){ cout << x << ' ' << y << endl; } return 0; }