//第二题代码 #include<bits/stdc++.h> using namespace std; const int maxn = 5*1e5 + 10; int num[maxn],s[maxn]; int r[maxn],l[maxn]; int main(){ int n; scanf("%d",&n); s[0] = 0; for(int i = 1; i <= n; i++){ scanf("%d",&num[i]); s[i] = s[i-1] + num[i]; } num[0] = -1; num[n+1] = -1; for(int i = 1; i <= n; i++){//求出左边比当前值小的第一个数 int k = i -1; while(num[i] <= num[k]) k = l[k]-1; l[i] = k+1; } for(int i = n; i >= 1; i--){ int k=i+1; while(num[i] <= num[k]) k=r[k]+1; r[i]=k-1; } int ans = -1; for(int i = 1; i <= n; i++){ ans = max(ans,num[i]*(s[r[i]] - s[l[i]-1])); } printf("%d\n",ans); }