#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  ll ans=0,maxi=0;
  rep(i,n){
    ll mini=1e8;
    for(ll j=i;j<n;j++){
      mini=min(mini,a.at(j));
      maxi=mini*(j-i+1);
      ans=max(ans,maxi);
    }
  }
  cout << ans;
}
    
#include <bits/stdc++.h>
using namespace std;

long long arr[100005];
int s[100005], top=0;
int l[100005], r[100005];

int main(){
	int n;
	cin >> n;
	arr[0] = arr[n+1] = -1;
	for (int i=1; i<=n; i++) cin >> arr[i];
	for (int i=1; i<=n; i++){
		while (arr[s[top]]>=arr[i]) top--;
		l[i] = i-s[top];
		s[++top]=i;
	}
	top=0;
	s[0]=n+1;
	for (int i=n; i>=1; i--){
		while (arr[s[top]]>=arr[i]) top--;
		r[i] = s[top]-i;
		s[++top]=i;
	}
	long long ans=0;
	for (int i=1; i<=n; i++){
		ans = max(ans, arr[i]*(l[i]+r[i]-1));
	}
	cout << ans;
	return 0;
}