#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int N,A;
  cin >> N;
  vector<int> vec,vec2;
  for(int i = 0;i<N;i++){
    cin >> A;
  	vec.push_back(A);
    vec2.push_back(A);
  }
  sort(vec2.begin(), vec2.end());
  int min = vec2.at(0);
  //cout << min << endl;
  int max = min * N;
  for(int i = 0;i < N;i++){
  	if(min < vec2.at(i)){
    	min = vec2.at(i);
      //cout << min << endl;
    }else{continue;}
    int cnt=0,cntmax=0;
    for(int j = 0;j < N;j++){
      
    	if(min <= vec.at(j)){
        	cnt++;
          if(cntmax < cnt){
              cntmax=cnt;
              //cout << cnt << endl;
            }
        }else{
        	if(cntmax < cnt){
              cntmax=cnt;
              //cout << cnt << endl;
            }
          //cout << cnt << endl;
          cnt = 0;
        }
    }
    if(max < cntmax*min)
    	max = cntmax*min;
  }
  cout << max << endl;
  return 0;
}
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define MOD 1000000007
#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

const int dx[4] = { -1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };




int main()
{

	fio;
	ll t,n,i,j,d,x,a,b;
    cin>>n;
    ll arr[n];
    for(i=0;i<n;i++)
    {
    	cin>>arr[i];
	}
	ll pref1[n],pref2[n];
	stack<ll>s;
	for(i=0;i<n;i++)
	{
		while(!s.empty()&&arr[s.top()]>=arr[i])
		s.pop();
		if(s.empty())
		{
			pref1[i]=-1;
		}
		else
		pref1[i]=s.top();
		s.push(i);
		
	}
	while(!s.empty())
	s.pop();
	for(i=n-1;i>=0;i--)
	{
			while(!s.empty()&&arr[s.top()]>=arr[i])
		s.pop();
		if(s.empty())
		{
			pref2[i]=n;
		}
		else
		pref2[i]=s.top();
		s.push(i);
		
	}
	ll ans=0;
	for(i=0;i<n;i++)
	{
		ll noe=(i-pref1[i])+(pref2[i]-i);
		noe-=1;
		ans=max(ans,arr[i]*noe);
		
		
	}
	cout<<ans;
	
	
	

	
}