#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

/*
1. If you cannot approach a problem
directly in the way it is proposed 
then try to think from backwards
2. Have you checked the implementation 
before starting to write the code?
3. Have you read the question carefully ?
4. Keep the names of variable descriptive.
5. Check the types and range of the values properly
6. Erase a iterator in the set or map only after using its value.
7. 1 bitset of 1e9 size only takes 256 mb.
8. Try to use global variables in case of recursion
9. Short and precise exectutes faster
*/
const int MAXN = 1e5 + 1, K = 20;
long long st[MAXN][K + 1];
int Log[MAXN + 1];

void initialize()
{
    Log[1] = 0;
    for (int i = 2; i <= MAXN; i++)
        Log[i] = Log[i / 2] + 1;
}

void preprocess(int N, vector<int> &array)
{
    for (int i = 0; i < N; i++)
        st[i][0] = array[i];

    for (int j = 1; j <= K; j++)
        for (int i = 0; i + (1 << j) <= N; i++)
            st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}

int Min(int L, int R)
{
    int j = Log[R - L + 1];
    return min(st[L][j], st[R - (1 << j) + 1][j]);
}

void solve()
{
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int &x: arr)
        cin >> x;
    initialize();
    preprocess(n, arr);
    vector<int> ans(n + 1 , 0);
    F(int, i, 0, n - 1, 1){
        int l = 0, r = i;
        while(l <= r){
            int mid = (l + r) >> 1;
            int cons = Min(mid, i);
            if(cons == arr[i]){
                r = mid - 1LL;
            }else{
                l = mid + 1LL;
            }
        }
        int go_l = r + 1LL;
        l = i, r = n - 1LL;
        while(l <= r){
            int mid = (l + r) >> 1;
            int cons = Min(i, mid);
            if(cons == arr[i]){
                l = mid + 1LL;
            }else{
                r = mid - 1LL;
            }
        }
        int go_r = l - 1LL;
        ans[go_r - go_l + 1LL] = max(ans[go_r - go_l + 1LL], arr[i]);
    }
    int ac = 0;
    F(int, l, 1, n, 1){
        ac = max(ac, ans[l] * l);
    }
    cout << ac;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        // freopen("Debug.txt", "w", stderr);
    #else
    #endif
    // cout << fixed << setprecision(10);
    // int _t;
    // cin>>_t;
    // while(_t --)
        solve();
}

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

const int MAX_N = 1e4+2;
int n;
ll a[MAX_N];

void solve()
{
  ll ans = 0;
  for(int i=0;i<n;++i){
  	ll mi = 1e6;
    for(int j=i;j<n;++j){
    	mi=min(mi, a[j]);
      	ans=max(ans,1LL*(j-i+1)*mi);
    }
  }
  cout<<ans<<'\n';
}

int main()
{
	cin >> n;
  	for(int i=0;i<n;++i)cin >> a[i];
  	solve();
  	return 0;
}