using namespace std; const int N = 1e7 + 5; int w[N]; int st[N]={-1}; long long top; int () { int n; while(cin>>n,n) { int temp; long long ans = 0; top = 0; for (int i = 1; i <= n+1;i++) { if(i!=n+1) cin >> temp; else temp=0; if(st[top]<temp) { st[++top] = temp; w[top] = 1; } else { long long cnt = 0; while(top>0&&st[top]>=temp) { ans = max(ans, (w[top] + cnt) * st[top]); cnt = cnt+ w[top--]; } st[++top]=temp; w[top] = cnt + 1; } } cout << ans << endl; } }