#!/bin/python3 import sys def gcd(a, b): while b: a, b = b, a%b return a def maximumValue(a): maximum=-999999 for x in range(len(a)): for y in range(x, len(a)): store=a[x] for z in a[x+1:y+1]: store=gcd(store, z) store=store*(sum(a[x:y+1])-max(a[x:y+1])) if store>maximum: maximum=store return maximum # Return the maximum value of f among all subsegments [l..r]. if __name__ == "__main__": n = int(input().strip()) a = list(map(int, input().strip().split(' '))) result = maximumValue(a) print(result)