#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  int ans = 0;
  for(int l = 0;l < n;l++){
    int x = a[l];
    for(int r = l;r < n;r++){
      x = min(x,a[r]);
      ans = max(ans,x*(r-l+1));
    }
  }
  cout << ans << endl;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;


mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
}

template<class ForwardIterator> void print_vec(ForwardIterator first,
		ForwardIterator last, string sep = " ", string end = "\n") {
	bool ft = true;
	while (first != last) {
		if (!ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
	int sign = lo <= hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = lo + floorDiv(hi-lo, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 10005;

int n;
ll num[MAXN];

//Max histogram area from geeksforgeeks 
//https://www.geeksforgeeks.org/largest-rectangle-under-histogram/
ll getMaxArea() { 
    
    stack<ll> s; 
  
    ll max_area = 0;
    int tp;
    ll area_with_top;
  
    int i = 0; 
    while (i < n) 
    { 
        
        if (s.empty() || num[s.top()] <= num[i]) 
            s.push(i++); 

        else
        { 
            tp = s.top();
            s.pop(); 

            area_with_top = num[tp] * (s.empty() ? i :  
                                   i - s.top() - 1); 
  
            if (max_area < area_with_top) 
                max_area = area_with_top; 
        } 
    } 
  
    while (s.empty() == false) 
    { 
        tp = s.top(); 
        s.pop(); 
        area_with_top = num[tp] * (s.empty() ? i :  
                                i - s.top() - 1); 
  
        if (max_area < area_with_top) 
            max_area = area_with_top; 
    } 
  
    return max_area; 
} 

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	
	for (int i=0; i < n; i++) {
		cin >> num[i];
	}
	
	cout << getMaxArea() << "\n";

	
}
