#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int n, top, ans, a[N];
int nums[N], w[N];
signed main() {
while (cin >> n && n) {
ans = 0, top = 0;
for (int i = 1; i <= n; i ++) scanf("%d", &a[i]);
a[n + 1] = 0;
for (int i = 1; i <= n + 1; i ++) {
if (a[i] > nums[top]) {
nums[++ top] = a[i];
w[top] = 1;
}
else {
int d = 0;
while (nums[top] > a[i]) {
d += w[top];
ans = max(ans, (int)d * nums[top]);
top --;
}
nums[++ top] = a[i], w[top] = d + 1;
}
}
printf("%d\n", ans);
}
return 0;
}