#include #define int long long using namespace std; const int N = 1e5 + 5, M = 25; int n, x, pref[N], stgc[M][N], stmx[M][N], step[N], ans; int gc(int l, int r){ int k = step[r - l + 1]; return __gcd(stgc[k][l], stgc[k][r - (1 << k) + 1]); } int mx(int l, int r){ int k = step[r - l + 1]; return max(stmx[k][l], stmx[k][r - (1 << k) + 1]); } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> x; pref[i] = pref[i - 1] + x; stgc[0][i] = stmx[0][i] = x; } for(int i = 2; i < N; i++){ step[i] = step[i / 2] + 1; } for(int i = 1; i <= step[n]; i++){ for(int j = 1; j + (1 << i) - 1 <= n; j++){ stgc[i][j] = __gcd(stgc[i - 1][j], stgc[i - 1][j + (1 << (i - 1))]); stmx[i][j] = max(stmx[i - 1][j], stmx[i - 1][j + (1 << (i - 1))]); } } for(int i = 1; i <= n; i++){ for(int j = i; j <= n; j++){ ans = max(ans, gc(i, j) * ((pref[j] - pref[i - 1]) - mx(i, j))); //cout << i << " " << j << " " << gc(i, j) << " " << pref[j] - pref[i - 1] << " " << mx(i, j) << "\n"; } } cout << ans; }