#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define mod 1000000007
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5*2+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };

int main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n,k,i,j,m;
cin>>n;
ll arr[n+5];
rep(i,0,n)
    cin>>arr[i];
vector <pair<ll, pair <ll,ll>>> v;
for(i=0;i<n;i++)
{
    for(j=0;j<n;j++)
    {
        v.pb({arr[i]*abs(j-i),{i,j}});
    }
}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
// for(auto it:v)
//     cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;
unordered_set <ll> s,s1;
ll sum=0;
for(auto it:v)
{
    if (s.find(it.se.fi) == s.end() and s1.find(it.se.se) == s1.end())
    {
        sum+=it.fi;
        s.insert(it.se.fi);
        // cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<"*\n";
        s1.insert(it.se.se);
    }
}
cout<<sum<<endl;
return 0;
}
