#include namespace nono { struct Init {}; void solve([[maybe_unused]] const Init& init) { int n; std::cin >> n; std::vector a(n); for (int i = 0; i < n; i++) std::cin >> a[i]; auto goodbye = [&](auto self, int n) -> void { if (n == 1) return; std::cout << n << ' ' << n - 1 << std::endl; self(self, n - 1); }; auto output = [&](int i, int j) -> void { std::cout << 0 << std::endl; std::cout << i + 1 << ' ' << j + 1 << std::endl; goodbye(goodbye, n - 1); }; if (std::ranges::find(a, 1) != a.end()) { int i = std::ranges::find(a, 1) - a.begin(); int j = (i + 1) % n; output(i, j); return; } if (std::ranges::find(a, 0) != a.end()) { int i = std::ranges::find(a, 0) - a.begin(); int j = (i + 1) % n; output(i, j); return; } constexpr int N = 200001; std::array, N> index; index.fill(std::vector()); for (int i = 0; i < n; i++) { int value = a[i]; for (int j = 2; j * j <= value; j++) { if (value % j == 0) { index[j].push_back(i); while (value % j == 0) { value /= j; } } } if (value != 1) { index[value].push_back(i); } } for (int i = 0; i < N; i++) { if (index[i].size() >= 2) { output(index[i][0], index[i][1]); return; } } if (n == 2) { long long x = a[0]; long long y = a[1]; std::cout << (x - 1) * (y - 1) << std::endl; goodbye(goodbye, 2); } else if (n == 3) { long long ans = 1e18; int ans_i = -1; for (int i = 0; i < 3; i++) { int j = (i + 1) % n; int k = (i - 1 + n) % n; long long v = (a[j] - 1) * (a[k] - 1); if (std::gcd(v, a[i]) != 1) { ans = 0; ans_i = i; break; } else if (ans > (v - 1) * (a[i] - 1)) { ans = (v - 1) * (a[i] - 1); ans_i = i; } } int j = (ans_i + 1) % n; int k = (ans_i - 1 + n) % n; std::cout << ans << std::endl; std::cout << j + 1 << ' ' << k + 1 << std::endl; goodbye(goodbye, 2); } else { std::cout << 0 << std::endl; auto it = std::ranges::find(a, 2); if (it == a.end() || (it - a.begin() >= 4)) { std::cout << 1 << ' ' << 2 << std::endl; std::cout << 1 << ' ' << 2 << std::endl; goodbye(goodbye, n - 2); } else { int i = (it - a.begin()); if (i == 0) { std::cout << 2 << ' ' << 3 << std::endl; std::cout << 1 << ' ' << n - 1 << std::endl; } else if (i == 1) { std::cout << 1 << ' ' << 3 << std::endl; std::cout << 1 << ' ' << n - 1 << std::endl; } else if (i == 2) { std::cout << 1 << ' ' << 2 << std::endl; std::cout << 1 << ' ' << n - 1 << std::endl; } else if (i == 3) { std::cout << 1 << ' ' << 2 << std::endl; std::cout << 2 << ' ' << n - 1 << std::endl; } goodbye(goodbye, n - 2); } } } } // namespace nono int main() { std::cin.tie(0)->sync_with_stdio(0); std::cout << std::fixed << std::setprecision(16); int t = 1; nono::Init init; while (t--) nono::solve(init); }