// Problem: C - Squared Error
// Contest: AtCoder - AtCoder Beginner Contest 194
// URL: https://atcoder.jp/contests/abc194/tasks/abc194_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Date: 2021-03-09 12:52:00
// --------by Herio--------

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull; 
const int N=3e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define IOS ios::sync_with_stdio(false),cin.tie(0) 
void Print(int *a,int n){
	for(int i=1;i<n;i++)
		printf("%d ",a[i]);
	printf("%d\n",a[n]); 
}
ll a[N],b[N],c[N];
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i],b[i]=a[i]+b[i-1],c[i]=c[i-1]+a[i]*a[i];
	ll s=0;
	for(int i=2;i<=n;i++){
		s+=(i-1)*a[i]*a[i]+c[i-1]-2*a[i]*b[i-1];
	}cout<<s<<'\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int mod=998244353;
#define ll long long
#define pb push_back
int a[maxn];



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int ans=0;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        int cnt=0;
        for(int j=i;j<=n;j++)
        {
            if(a[j]<a[i])
                break;
            cnt++;
        }
        for(int j=i-1;j>=1;j--)
        {
            if(a[j]<a[i])
                break;
            cnt++;
        }
        ans=max(ans,cnt*a[i]);
    }
    cout<<ans<<'\n';


}
