#include #include #include #include #include #include #include #include #include using namespace std; typedef vector tVI; typedef set tSI; struct rect { int from; int height; rect(int f, int h):from(f), height(h) { } }; bool operator<(const rect &a, const rect &b) { return a.height < b.height; } ifstream in("histogram.in"); typedef priority_queue tPQ; int main() { int n; while (in >> n) { if (!n) break; tVI v; for (int i=0; i> tmp; v.push_back(tmp); } long long A = 0; tPQ p; tSI s; if (v[0]) { p.push(rect(0, v[0])); // s.insert(v[0]); } for (int cur=1; cur<(int)v.size(); cur++) { while (!p.empty()) { if (p.top().height <= v[cur]) break; // sonst ausrechnen und rausnehmen long long test = (long long) ((long long)cur-p.top().from) * p.top().height; if (test > A) A = test; rect r = p.top(); // s.erase(p.top().height); p.pop(); if (v[cur]) p.push(rect(r.from, v[cur])); } if (p.empty()) { p.push(rect(cur,v[cur])); // s.insert(v[cur]); } else if (p.top().height < v[cur]) { p.push(rect(cur,v[cur])); // s.insert(v[cur]); } else if (p.top().height == v[cur]); else { if (s.find(v[cur]) != s.end()); else { p.push(rect(cur, v[cur])); // s.insert(v[cur]); } } } while (!p.empty()) { long long test = (long long) ((long long) v.size()-p.top().from) * p.top().height; if (test > A) A = test; p.pop(); } cout << A << endl; } return 0; }