#include #define boost std::ios::sync_with_stdio(false) using namespace std; #define ll long long #define pb push_back int power(ll x, ll y) { ll res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x); // n must be even now y = y>>1; // y = y/2 x = x*x; // Change x to x^2 } return res; } // This function prints the longest palindrome substring (LPS) // of str[]. It also returns the length of the longest palindrome int longestPalSubstr(vector str) { int maxLength = 1; // The result (length of LPS) int start = 0; int len = str.size(); int low, high; // One by one consider every character as center point of // even and length palindromes for (int i = 1; i < len; ++i) { // Find the longest even length palindrome with center points // as i-1 and i. low = i - 1; high = i; while (low >= 0 && high < len && str[low] == str[high]) { if (high - low + 1 > maxLength) { start = low; maxLength = high - low + 1; } --low; ++high; } // Find the longest odd length palindrome with center // point as i low = i - 1; high = i + 1; while (low >= 0 && high < len && str[low] == str[high]) { if (high - low + 1 > maxLength) { start = low; maxLength = high - low + 1; } --low; ++high; } } //printf("Longest palindrome substring is: "); //printSubStr(str, start, start + maxLength - 1); return maxLength; } //set S; map::iterator it; string s; int main() { boost; int n; cin>>n; ll ar[n+1],gcd[n+1][n+1],maxi[n+1][n+1],sum[n+1][n+1]; for(int i=1;i<=n;i++) cin>>ar[i]; for (int i = 1; i <= n; ++i) { gcd[i][i-1]=ar[i]; maxi[i][i-1]=ar[i]; sum[i][i-1]=0; for (int j = i; j <= n; ++j) { gcd[i][j] = __gcd(ar[j], gcd[i][j - 1]); maxi[i][j]=max(ar[j],maxi[i][j-1]); sum[i][j]=sum[i][j-1]+ar[j]; } } ll ans=LONG_LONG_MIN; for (int i = 1; i <=n ; ++i) { for (int j = i; j <=n ; ++j) { if(ans<(gcd[i][j]*(sum[i][j]-maxi[i][j]))) ans=(gcd[i][j]*(sum[i][j]-maxi[i][j])); } } cout<