#include using namespace std; const int maxn = 50002; const int64_t inf = 1e18; int n, a[maxn]; int main() { //freopen("abstract.inp", "r", stdin); ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i=1; i<=n; ++i) { cin >> a[i]; } int64_t res = 0; for (int i=1; i<=n; ++i) { int g = a[i], MAX = -1e9; int64_t s = 0; for (int j=i; j<=n; ++j) { g = __gcd(g, a[j]); s += a[j]; MAX = max(MAX, a[j]); res = max(res, g*(s-MAX)); } } cout << res; }