import java.io.BufferedReader; import java.io.InputStreamReader; public class StrangeFunction { private int[] a; private int size; private Data[] heap; public StrangeFunction (int[] a) { this.a = a; size = (int) (2 * Math.pow(2.0, Math.floor((Math.log((double) a.length) / Math.log(2.0)) + 1))); heap = new Data[size]; //Arrays.fill(heap, -1); build(1, 0, a.length - 1); } public void build(int node, int lo, int hi) { if (lo == hi) { heap[node] = new Data(a[lo], a[lo], a[lo]); // heap[node].max = a[lo]; // heap[node].sum = a[lo]; // heap[node].gcd = a[lo]; } else { int mid = lo + (hi - lo) / 2; build(node * 2, lo, mid); build(node * 2 + 1, mid + 1, hi); heap[node] = new Data(); // gcd update heap[node].gcd = gcd(heap[node * 2].gcd, heap[node * 2 + 1].gcd); // sum update heap[node].sum = heap[node * 2].sum + heap[node * 2 + 1].sum; // max update heap[node].max = Math.max(heap[node * 2].max, heap[node * 2 + 1].max); } } public Data query(int l, int r) { return query(1, 0, a.length - 1, l, r); } private Data query(int node, int start, int end, int l, int r) { if (l > end || r < start) return new Data(0, Integer.MIN_VALUE, 0); if (l <= start && end <= r) return heap[node]; int mid = start + (end - start) / 2; Data p1 = query(node * 2, start, mid, l, r); Data p2 = query(node * 2 + 1, mid + 1, end, l, r); return new Data(p1.sum + p2.sum, Math.max(p1.max, p2.max), gcd(p1.gcd, p2.gcd)); } public static int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); int[] a = new int[n]; String[] raw_data = br.readLine().split("\\s+"); for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(raw_data[i]); } int max = Integer.MIN_VALUE; StrangeFunction sf = new StrangeFunction(a); for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { Data d = sf.query(i, j); max = Math.max(max, d.gcd * (d.sum - d.max)); } } System.out.println(max); } } class Data { int sum; int max; int gcd; public Data (int sum, int max, int gcd) { this.sum = sum; this.max = max; this.gcd = gcd; } public Data() {} }