#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
#define endl '\n'
int n;
int a[2000005];
inline int read(){
char c = getchar();int x =0;
while(c<'0' or c>'9')c = getchar();
while('0'<=c and c<='9')x= x*10+(c^48),c = getchar();
return x;
}int ls[2000005],rs[2000005],mx[2000005];
int st[2000005];int head = 1;
__int128 ans = 0;
void write(__int128 x){
if(x>=10)write(x/10);
putchar('0'+x%10);return;
}
int rt = 0;
inline int dfs(int x){
mx[x] = a[x];int len = 1;
if(ls[x])len+=dfs(ls[x]),mx[x] = max(mx[x],mx[ls[x]]);
if(rs[x])len+=dfs(rs[x]),mx[x] = max(mx[x],mx[rs[x]]);
ans = max(ans,(__int128)a[x]*(__int128)mx[x]*(__int128)len);
// cout << a[x] << " " << mx[x] << " " << len << endl;
// cout << x << " " << a[x] << " " << mx[x] << " " << len << endl;
return len;
}
signed main(){
n = read();
for(int i = 1;i<=n;i++)a[i] = read();
st[1] = 1;
for(int i= 2;i<=n;i++){
while(head and a[st[head]]>=a[i])head--;
if(!head){
rt = i;ls[i] = st[head+1];
}else ls[i] = rs[st[head]],rs[st[head]] = i;
st[++head] = i;
}
dfs(rt);write(ans);
//cout << (long long)ans << endl;
return 0;
}