This documentation is automatically generated by online-judge-tools/verification-helper
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C
#include<bits/stdc++.h>
using namespace std;
#define call_from_test
#include "../../algorithm/largestrectangle.cpp"
#undef call_from_test
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin>>n;
using ll = long long;
vector<ll> vs(n);
for(int i=0;i<n;i++) cin>>vs[i];
cout<<largestrectangle(vs)<<endl;
return 0;
}
#line 1 "test/aoj/DPL_3_C.test.cpp"
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C
#include<bits/stdc++.h>
using namespace std;
#define call_from_test
#line 1 "algorithm/largestrectangle.cpp"
#line 3 "algorithm/largestrectangle.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
T largestrectangle(vector<T> &v){
int n=v.size();
T res=0;
using P = pair<int, T>;
stack<P> sp;
sp.emplace(-1,T(0));
for(int i=0;i<n;i++){
int j=i;
while(sp.top().second>v[i]){
j=sp.top().first;
res=max(res,(i-j)*sp.top().second);
sp.pop();
}
if(sp.top().second<v[i]) sp.emplace(j,v[i]);
}
while(!sp.empty()){
res=max(res,(n-sp.top().first)*sp.top().second);
sp.pop();
}
return res;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
return 0;
}
#endif
#line 8 "test/aoj/DPL_3_C.test.cpp"
#undef call_from_test
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
int n;
cin>>n;
using ll = long long;
vector<ll> vs(n);
for(int i=0;i<n;i++) cin>>vs[i];
cout<<largestrectangle(vs)<<endl;
return 0;
}