#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int N, A, ans=0; cin >> N; vector<int> T;
stack< vector<int> > S; S.push({0, -1});
REP(i, N+1){ 
  if(i<N){ cin >> A; }else{ A=0; }
  T=S.top();
  if(A>T[0]){ S.push({A, i}); continue; }
  while(A<T[0]){
    ans=max(ans, T[0]*(i-T[1])); 
    S.pop(); T=S.top();
  }
  S.push({A, T[1]+1}); S.push({A, i});
}
cout << ans << "\n";
}
#include <bits/stdc++.h>

using namespace std;

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

#define rng_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define int long long

const int MXN = 1e5 + 5, INF = 1e9 + 5;

void solve() {
    int N;
    cin >> N;

    vector<int> A(N);
    for (auto &x : A) cin >> x;

    int ans = 0;

    for (int i = 0; i < N; i++) {
        int mn = A[i];
        for (int j = i; j < N; j++) {
            mn = min(mn, A[j]);
            ans = max(ans, (j - i + 1) * mn);
        }
    }

    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef local
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
//    cin >> TC;
    while (TC--) solve();
}