
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair  <int,int> ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set   <int>     si;
typedef set   <ii>      sii;
typedef vi::iterator itt;
typedef si::iterator jtt;

#define fori(i,x) for(itt i=x.begin();i!=x.end();i++)
#define forj(j,x) for(jtt j=x.begin();j!=x.end();j++)
#define all(x)   x.begin(), x.end()
#define clr(x,v) memset(x,v,sizeof(x))

#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define endl "\n"
#define MOD int(1e9+7)
#define N 2123
ll n, a, b,  ma, mb, ans, v[N];
int moveu[N];
pair<ll,ii> move;
int main(){_
    cin >> n;
    a=0, b = n-1;
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<n;i++){
        move.x=-1;
        for(int j=0;j<n;j++){
            if(moveu[j])continue;
            ma = abs(j-a)*v[j];
            mb = abs(j-b)*v[j];
            if(ma>mb){
                if(ma>move.x||(ma==move.x && v[j]<v[move.y.x])){
                    move = mp(ma,mp(j,0));
                }
            }
            else{
                if(mb>move.x||(mb==move.x && v[j]<v[move.y.x])){
                    move = mp(mb,mp(j,1));
                }
            }
        }
        
        ans+=move.x;
        int id = move.y.x, dir = move.y.y;
        moveu[id] = 1;
        //cout<<a<<' '<<b<<endl;
        //cout<<id<<' '<<dir<<' '<<move.x<<endl;
        if(dir==0){
            a++;
        }
        else{
            b--;
        }
    }
    cout << ans << endl;
}