```
#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("%lld\n", ans);
}
return 0;
}
```
by CYC_er @ 2020-08-19 00:10:37
@[include6666](/user/244147) %%%感谢大佬
by kemkra @ 2020-08-19 00:12:17