using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; if (n == 2) { WriteLine(Coin(a[0], a[1])); WriteLine("1 2"); return; } if (n == 3) { var min = long.MaxValue; var minorder = ""; { var m = Coin(Coin(a[0], a[1]), a[2]); if (m < min) { m = min; minorder = "1 2\n1 2"; } } { var m = Coin(Coin(a[0], a[2]), a[1]); if (m < min) { m = min; minorder = "1 3\n1 2"; } } { var m = Coin(Coin(a[1], a[2]), a[0]); if (m < min) { minorder = "2 3\n1 2"; } } WriteLine(min); WriteLine(minorder); return; } WriteLine(0); WriteLine("1 2\n1 2"); for (var i = n - 2; i >= 2; --i) { WriteLine($"1 {i}"); } } static long Coin(long a, long b) { checked { if (a == 0 || b == 0) return 0; if (GCD(a, b) > 1) return 0; return (a - 1) * (b - 1); } } static long GCD(long a, long b) { if (a < b) return GCD(b, a); if (a % b == 0) return b; return GCD(b, a % b); } }