Code:
#include <bits/stdc++.h> #define setIO(s) freopen(s".in","r",stdin) #define maxn 100004 #define ll long long using namespace std; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; } ll arr[maxn],gc[maxn]; int pos[maxn],b[maxn]; int main() { // setIO("input"); int n,i,j,top=0,tmp=0; ll ans=0; scanf("%d",&n); for(i=1;i<=n;++i) { scanf("%lld",&arr[i]); for(j=1;j<=top;++j) gc[j]=gcd(gc[j],arr[i]); gc[++top]=arr[i], pos[top]=i; b[tmp=1]=1; for(j=2;j<=top;++j) if(gc[j]!=gc[j-1]) b[++tmp]=j; top=0; for(j=1;j<=tmp;++j) { gc[++top]=gc[b[j]],pos[top]=pos[b[j]]; ans=max(ans,1ll*(i-pos[top]+1)*gc[top]); } } printf("%lld\n",ans); return 0; }