#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define f(i,a, b) for (ll i = a; i < b; i++)
#define ft int t; cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define ld float
#define fd(i,a, b) for (ll i = a; i >= b; i--)
#define nl "\n"
 /*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/



int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
  ll n;
  cin>>n;
  ll aa[n];
  f(i,0,n)cin>>aa[i];
  multimap<ll, pair <int,int> ,greater<ll> > mm;
  f(i,0,n){
    f(j,0,n){
       ll val=aa[i]*abs(i-j);
       mm.insert({val,mp(i,j)});
    }
  }
  bool co1[n]={0},co2[n]={0};
  ll sm=0;
  for(auto ii=mm.begin();ii!=mm.end();ii++){
     ll val=ii->first;
     ll ind=ii->second.first;
     ll ind2=ii->second.second;
     if(co1[ind]==0 && co2[ind2]==0){
        sm+=val;
        co1[ind]=1; co2[ind2]=1;
     }

  }
  cout<<sm<<endl;
}
