//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

ll expo(ll a,ll b,ll m){
    if(b<0)return expo(expo(a,m-2,m),-b,m);
    ll res=1;
    while(b>0){
        if(b&1)res=(res*a)%mod;
        a=(a*a)%mod;
        b=b/2;
    }
    return res;
}

int main()
{
    int n;cin>>n;
    vector<ll> v(n);
    rep(i,0,n)cin>>v[i];

    ll l=0,r=n-1;
    ll mx=0;
    ll ans=0;
    bool vis[n];mem(vis,0);
    rep(i,0,n){
        pair<ll,ll> vl=mp(0,0),vr=mp(0,0);
        rep(j,0,n){
            if(vis[j])continue;
            ll vall=abs(l-j)*v[j];
            ll valr=abs(r-j)*v[j];
            if(vall>=vl.F){
                vl.F=vall;
                vl.S=j;
            }
            if(valr>vr.F){
                vr.F=valr;
                vr.S=j;
            }
        }
        if(vl.F>vr.F){
            ans+=(vl.F);
            vis[vl.S]=true;
            l++;
        }
        else if(vr.F>vl.F){
            ans+=(vr.F);
            vis[vr.S]=true;
            r--;
        }
        else{
            ll ldif=abs(vl.S-l);
            ll rdif=abs(vr.S-r);
            if(ldif>rdif){
                ans+=(vl.F);
                vis[vl.S]=true;
                l++;
            }
            else{
                ans+=(vr.F);
                vis[vr.S]=true;
                r--;
            }
        }
    }
    cout<<ans;
}
