#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pairI2;
typedef pair<LL, LL> pairLL2;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<VI> VVI;
typedef vector<string> VS;
#define shig_for(i, a, b) for(int i = (a); i < (b); ++i)
#define shig_rep(i, n) shig_for(i, 0, n)
#define shig_forB(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit)
#define shig_repB(bit,n) shig_forB(bit,0,n)
#define CINLL(a) LL (a); cin >> (a)
#define CINI2(a, b) int a, b; cin >> (a) >> (b)
#define CINLL2(a, b) LL a, b; cin >> (a) >> (b)
#define tmp int temp = 0
#define str string s

struct Rect{
  int rightIdx;
  int leftIdx;
  int height;
};

LL maxHistogramRect(VI &histogram)
{
  LL maxArea = 0;
  int histogramSize = histogram.size();
  stack<Rect> weightStack;
  for (int i = 0; i < histogramSize; i++){
    Rect newRect;
    newRect.height = histogram[i];
    //空なのは最初だけ、それ以降は空でないことが保証できる
    if (weightStack.empty()){
        newRect.leftIdx = i;
        weightStack.push(newRect);
        maxArea = 1 * newRect.height;
    }else{//取り出されたものは戻されることはなく、一方通行だからO(n)
        int lastLeftIdx = i;
        while (!weightStack.empty() && weightStack.top().height > histogram[i]){
        weightStack.top().rightIdx = i - 1;
        int area = (weightStack.top().rightIdx - weightStack.top().leftIdx + 1) * weightStack.top().height;
        if(maxArea < area)maxArea = area;
        lastLeftIdx = weightStack.top().leftIdx;
        weightStack.pop();
        }
        Rect newRect;
        newRect.height = histogram[i];
        newRect.leftIdx = lastLeftIdx;
        weightStack.push(newRect);
    }
  }
  //weightStackに残ったものについての面積を計算する
  while (!weightStack.empty()){
    weightStack.top().rightIdx = histogramSize - 1;
    int area = (weightStack.top().rightIdx - weightStack.top().leftIdx + 1) * weightStack.top().height;
    if(maxArea < area)maxArea = area;
    weightStack.pop();
  }
  return maxArea;
}

int main(){

    LL N;
    cin >> N;
    VI A(N);
    shig_rep(i, N)cin >> A[i];

    LL ans = maxHistogramRect(A);

    cout << ans << endl;
    //for(string& s : S) cin >> s;
    //cout << "Atcoder " << N << endl;
    //cout << fixed << setprecision(10) << ans << endl;

    return 0;
}
# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define cauto const auto
# define int long long
# define float long double
# define fi first
# define se second
# define mkp make_pair
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
# define contains(x,key) ((x).find(key) != (x).end())
# define lb(v,x) distance(std::begin(v), lower_bound(all(v), (x)))
# define ub(v,x) distance(std::begin(v), upper_bound(all(v), (x)))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using mii = map<int, int>;
using mci = map<char, int>;
using msi = map<string, int>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
constexpr float PI = 3.1415926535897932385;
constexpr int Flag(int n) { return 1LL << n; }
template<class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T> istream& operator>>(istream& is, vector<vector<T>>& v) { for(auto& x : v) for (auto& y : x) is >> y; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> string join(const vector<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vector<T>& v){ if (len(v)) os << join(v); return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){ rep (i, len(v)) { if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ cout << p.fi << " " << p.se; return os; }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; print(args...);}
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){cerr << v; if(sizeof...(args))cerr << " "; eprint(args...);}
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){cout << v; if(sizeof...(args))cout << " "; drop(args...);}
template<class T> inline void Unique(T& v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }
template<class T> inline constexpr bool chmax(T &a, T b) { return a < b && (a = b, true); }
template<class T> inline constexpr bool chmin(T &a, T b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
const char* YesNo(bool b) { return b ? "Yes" : "No"; }
const char* YESNO(bool b) { return b ? "YES" : "NO"; }
const char* yesno(bool b) { return b ? "yes" : "no"; }
const char* yn(bool b) { return YesNo(b); }
# endif  // ngng628_library

int32_t main() {
   int n;
   cin >> n;
   vi a(n);
   cin >> a;
   int ans = 0;
   rep (l, n) {
      int mn = INF;
      repr (r, l, n) {
         chmin(mn, a[r]);
         int ln = r - l + 1;
         chmax(ans, mn*ln);
      }
   }
   print(ans);
}
