#include using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; #define X first #define Y second #define SZ(a) ((int)a.size()) #define ALL(v) v.begin(), v.end() #define pb push_back const ll INF = 9e18; ll f(ll p, ll q) { if (p == 0 && q == 0) return 0; if (gcd(p, q) == 1) return p * q - p - q + 1; return 0; } int main() { ios::sync_with_stdio(0), cin.tie(0); int n; cin >> n; ll best_v = INF; vector ans; vector arr(n); for (ll &i : arr) cin >> i; auto op = [&](int a, int b) { ans.pb(pii(a + 1, b + 1)); if (a > b) swap(a, b); ll res = f(arr[a], arr[b]); arr.erase(arr.begin() + b); arr.erase(arr.begin() + a); arr.pb(res); }; if (SZ(arr) <= 3) { vector best_ans; auto _dfs = [&](auto dfs) { if (SZ(arr) == 1) { if (best_v > arr[0]) best_v = arr[0], best_ans = ans; return; } vector tmp = arr; for (int i = 0; i < SZ(arr); ++i) for (int j = i + 1; j < SZ(arr); ++j) { op(i, j); dfs(dfs); arr = tmp, ans.pop_back(); } }; _dfs(_dfs); ans.swap(best_ans); } else { while (true) { vector even, odd; for (int i = 0; i < SZ(arr); ++i) if (arr[i] % 2 == 0) even.pb(i); else odd.pb(i); if (SZ(even) >= 2) { op(even[SZ(even) - 2], even.back()); break; } else op(odd[SZ(odd) - 2], odd.back()); } assert(arr.back() == 0); while (SZ(arr) > 1) { op(SZ(arr) - 2, SZ(arr) - 1); } best_v = 0; } cout << best_v << "\n"; for (auto [a, b] : ans) cout << a << " " << b << "\n"; }