#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define Time (double)clock()/CLOCKS_PER_SEC
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pi;
template <class T> void chmax(T &x,T y) {x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y) {x=x<y?x:y;return;}
template <class T> T sqr(T x) {return x*x;}
template <class T> T gcd(T x,T y) {return y==0?x:gcd(y,x%y);}
template <class T> T lcm(T x,T y) {return x/gcd(x,y)*y;}
const int inf=1000000000,mod=1000000007;
const ll infll=1000000000000000000ll,modll=ll(mod);
const db maxdb=db(infll),eps=1e-14,PI=acos(-1.0);
//#define mydef
//#define LOCAL
#ifdef mydef
#define foreach(v,it) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#endif
#define debug
#define putnum(x) cout<<#x<<": "<<x<<endl
#define putvec(v) cout<<#v<<": ";REP(i,0,sz(v)) cout<<v[i]<<" ";cout<<endl
template <class T> inline void read(T &x){
	T w=1;x=0;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
	x*=w;
}
template <class T> inline void write(T x) {
	if(x<0) putchar('-'),x=~x+1;
	if(x) write(x/10),putchar(x%10+'0');
}


const int maxn=700005;
int n,ans;
int a[maxn],l[maxn],r[maxn];
set<pi,greater<pi> > num;

void Get(int f,int *arr) {
	num.clear();
	for(int i=(f==1?1:n);i&&i<=n;i+=f) {
		while(!num.empty()&&(*num.begin()).fi>a[i]) {
			arr[(*num.begin()).se]=f==1?i-1:i+1;
			num.erase(num.begin());
		}
		num.insert(mp(a[i],i));
	}
	while(!num.empty()) {
		arr[(*num.begin()).se]=(f==1?n:1);
		num.erase(num.begin());
	}
//	if(f==-1) cout<<arr[2]<<endl;
}

int main() {
	#ifdef LOCAL
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	Get(1,r);
	Get(-1,l);
	for(int i=1;i<=n;i++)
		ans=max(ans,(r[i]-l[i]+1)*a[i]);
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int N, ret = 0; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int m = 0;
  for (int i = 0; i < N; i++) {
    m = A[i];
    for (int j = i; j < N; j++) {
      m = min(m, A[j]);
      ret = max(ret, m * (j - i + 1));
    }
  }

  cout << ret << endl;
  return 0;
}