#include <cstdio>
#include <stack>
#include <algorithm>
using namespace std;
stack<long long> s;
int n, w;
long long h, ans;
int main() {
while (scanf("%d", &n) && n) {
for (int i = 0; i < n; i++) {
scanf("%lld", &h);
while (!s.empty() && h < s.top()) {
ans = max(ans, s.top() * ++w);
s.pop();
}
s.push(h);
w = 0;
}
while (!s.empty()) {
ans = max(ans, s.top() * ++w);
s.pop();
}
printf("%d\n", ans);
}
return 0;
}