using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long maximumValue(int[] a) { long? max = null; for (int i = 0; i < a.Length; i++) for (int j = 0; j < a.Length; j++) { // Console.WriteLine($"{GCD(a[i], a[j])} * ({a[i] + a[j]} - {(a[i] > a[j] ? a[i] : a[j])})"); var m = GCD(a[i], a[j]) * ((i == j ? a[i] : a[i] + a[j]) - (a[i] > a[j] ? a[i] : a[j])); //Console.WriteLine($"{i} {j} :{m}"); if (max == null || max < m) max = m; } return max.Value; } public static long GCD(int p, int q) { p = Math.Abs(p); q = Math.Abs(q); if (q == 0) { return p; } int r = p % q; return GCD(q, r); } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); int[] a = Array.ConvertAll(a_temp, Int32.Parse); long result = maximumValue(a); Console.WriteLine(result); //Console.ReadKey(); } }