#include <iostream>
#define int long long int
using namespace std;
int32_t main()
{
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++) cin >> arr[i];

	int oranges = 0;
	for(int i = 0; i < n; i++)
	{
		int small = arr[i];
		for(int j = i; j < n; j++)
		{
			small = min(small, arr[j]);
			oranges = max(oranges, (j - i + 1) * small);
		}
	}
	cout << oranges << '\n';
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define vld vector<long double>
#define pll pair<long long int,long long int>
/* unordered_map<int,int>mp; mp.reserve(1024); mp.max_load_factor(0.25); */
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 1e6 + 5;
const ll inf = 1e9;

void solve()
{       
        ll n;
        cin >> n;
        vll a(n);
        map<ll,ll> f;
        set<ll> s;
        for(auto &x:a)
                cin >> x , s.insert(x) , f[x]++;
        ll ans = 0;
        for(auto x:s)
        {
                for(auto y:s)
                {
                        ans += (x-y)*(x-y)*f[x]*f[y];
                }
        }
        cout << ans/2;
}

void debug(ll tt) {}
 
signed main()
{
        FAST;
        int t = 1;
        // cin >> t;
        while(t--)
        {
                solve();
        }
}
