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

#define fi first
#define se second

int main() {
	long long int ans = 0, n;
	long long value;
	map<long long, long long> a;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> value;
		for(auto v : a) {
			ans += ((value - v.fi) * (value - v.fi) * v.se);
		}
		a[value]++;
	}
	cout << ans << endl;
	return 0;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
 
#define speed ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0)
#define fre freopen("in.txt","r",stdin),freopen("out.txt","w",stdout)
#define N 2*100005
#define M 2002
#define st first
#define nd second
#define endl "\n"
#define pb push_back
#define mp make_pair
#define inf 1e9+7
#define mid (start+end)/2
#define sp " "
#define Endl endl
typedef long long int ll;
 
ll x,y,w,n,m,pl,pr,flag,ans,k;


ll a[N];

void solve(){
    cin>>n;
    ll mn=1000000009;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    for (int i = 0; i < n; ++i)
    {
    	for (int j = i; j < n; ++j)
    	{
    		mn=min(mn,a[j]);	
    		ans=max(ans,mn*(j-i+1));
    	}
    	mn=1000000009;
    }
    cout<<ans;
}   
 
 
int main()
{
    speed;
    int TT=1;
    //cin>>TT;
    while(TT--)
        solve();
    return 0;
} 