/* -*- coding: utf-8 -*- * * 2519.cc: No.2519 Coins in Array - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ typedef long long ll; typedef pair pii; /* global variables */ int as[MAX_N]; pii ops[MAX_N]; /* subroutines */ template T gcd(T m, T n) { // m >= 0, n >= 0 if (m < n) swap(m, n); while (n > 0) { T r = m % n; m = n; n = r; } return m; } ll f(ll x, ll y) { ll g = gcd(x, y); return (g == 1) ? (x - 1) * (y - 1) : 0; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); ll mina = 0; if (n == 2) { mina = f(as[0], as[1]); ops[0] = pii(0, 1); } else if (n == 3) { ll f0 = f(f(as[0], as[1]), as[2]); ll f1 = f(f(as[0], as[2]), as[1]); ll f2 = f(f(as[1], as[2]), as[0]); if (f0 <= min(f1, f2)) mina = f0, ops[0] = pii(0, 1); else if (f1 <= f2) mina = f1, ops[0] = pii(0, 2); else mina = f2, ops[0] = pii(1, 2); ops[1] = pii(0, 1); } else { mina = 0; for (int i = 0; i < n - 1; i++) ops[i] = pii(0, 1); } printf("%lld\n", mina); for (int i = 0; i < n - 1; i++) printf("%d %d\n", ops[i].first + 1, ops[i].second + 1); return 0; }