#include #define loop(i,n) for( ll i=0; i::iterator i=a.begin(); i!=a.end(); i++ ) #define dloop(i,a) for( deque::iterator i=a.begin(); i!=a.end(); i++ ) #define PI 3.14159265 #define bc __builtin_popcountll #define gc getchar_unlocked #define pc putchar_unlocked #define pb push_back #define pf push_front #define rf pop_front #define rb pop_back #define mp make_pair #define fs first #define sc second #define fi ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; typedef long long ll; typedef unsigned long long ull; const ll M = 1e9 + 7; const ll INF = 1e9; inline ll pwr(ll base,ll n,ll m){ll ans=1;while(n>0){if(n%2==1)ans=(ans*base)%m;base=(base*base)%m;n/=2;}return ans;} const int sz = (int)5e4 + 10; ll st[4*sz][3], a[sz], n, GCD, SUM, MX; void init( int l, int r, int pos ) { if( l==r ) { st[pos][0] = a[l]; st[pos][1] = a[l]; st[pos][2] = a[l]; return; } int md = (l+r)>>1; init(l,md,pos*2+1); init(md+1,r,pos*2+2); st[pos][0] = __gcd(st[pos*2+1][0], st[pos*2+2][0]); st[pos][1] = max(st[pos*2+1][1], st[pos*2+2][1]); st[pos][2] = st[pos*2+1][2] + st[pos*2+2][2]; } void geta( int l, int r, int ql, int qr, int pos ) { if( ql > r || qr < l ) return; if( ql <= l && qr >= r ) { SUM += st[pos][2]; GCD = __gcd(GCD,st[pos][0]); MX = max(MX,st[pos][1]); return; } int md = (l+r)>>1; geta(l,md,ql,qr,pos*2+1); geta(md+1,r,ql,qr,pos*2 + 2); } int main() { fi; cin>>n; loop(i,n) cin>>a[i]; init(0,n-1,0); ll ans, res; loop(i,n) { loop1(j,i,n) { MX = -(int)1e9; GCD = 0; SUM = 0; geta(0,n-1,i,j,0); res = GCD*(SUM-MX); if( i == j && i == 0 ) ans = res; else ans = max(ans,res); } } cout<