#include #include #include #include #include #include using namespace std; // ----- TYPES ----- typedef long long ll; typedef pair pii; typedef vector vi; // ----- FILE IO ----- #define STDIN(filename) freopen(filename, "r", stdin) #define STDOUT(filename) freopen(filename, "w", stdout) #define FASTIO cin.tie(0)->sync_with_stdio(0) #define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str()) #define NL '\n' #define CM ", " // ----- FOR LOOPS ----- #define F(i,L,R) for (int i = L; i < R; i++) #define FE(i,L,R) for (int i = L; i <= R; i++) #define FD(i,L,R) for (int i = L; i > R; i--) #define FDE(i,L,R) for (int i = L; i >= R; i--) // ----- WEZ ----- #define takeI(n) int n; cin >> n #define takeII(n,m) int n, m; cin >> n >> m #define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k #define takeL(n) ll n; cin >> n #define takeS(s) string s; cin >> s #define takeV(v,n) vi v(n); for (auto &x : v) cin >> x #define takeVL(v,n) vector v(n); for (auto &x : v) cin >> x #define whileZ takeI(T); while(T--) // // ----- MAX MIN ----- #define REMAX(a,b) (a)=max((a),(b)) #define REMIN(a,b) (a)=min((a),(b)) // ----- PAIRS ----- #define fi first #define se second // ----- OUTPUT ----- #define YESNO(b) cout << ((b) ? "YES" : "NO") << NL // ----- DEBUG ----- #define DBG(vari) cerr<<#vari<<" = "<<(vari)<()) #define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end()) #define pb push_back int main() { STDIO("histogram"); // [1,2,3,4] string s; getline(cin, s); for (char &c : s) if (!isdigit(c) && c != '-') c = ' '; stringstream ss(s); vector h; int x; while (ss >> x) h.push_back(x); int n = h.size(); stack> stk; vector left(n), right(n); F(i,0,n) { int l = i; while (!stk.empty() && stk.top().first > h[i]) { l = stk.top().second; stk.pop(); } if (l != i) l = left[l]; left[i] = l; stk.push({h[i], i}); } FDE(i,n-1,0) { int r = i; while (!stk.empty() && stk.top().first > h[i]) { r = stk.top().second; stk.pop(); } if (r != i) r = right[r]; right[i] = r; stk.push({h[i], i}); } int res = 0; F(i,0,n) { int width = (right[i] - left[i] + 1); int new_res = width * h[i]; REMAX(res, new_res); } cout << res; }