#include<bits/stdc++.h>
using namespace std;
#define flb(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18+1e15)
typedef pair<int,int> ii;
typedef vector <int> vi;
typedef vector <pair<int,int> > vii;
typedef vector <vector <int> > vvi;

int main()
{
    int n;
    cin>>n;
    vi v(n);
    flb(i,0,n)
    cin>>v[i];
    int occupied[n+1]={0};
    int ma=n-1,mi=0;
    ll ans=0;
    flb(i,0,n)
    {
        map <int,int> m;
        vi li(n);
        int maxi=INT_MIN;
        flb(j,0,n)
        {
            if(v[j]==-1)
                continue;
            int temp1=abs(j-ma)*v[j];
            int temp2=abs(j-mi)*v[j];
            if(temp1>temp2)
            {
                li[j]=1;
                m[temp1]=j;
                maxi=max(maxi,temp1);
            }
            else
            {
                li[j]=0;
                m[temp2]=j;
                maxi=max(maxi,temp2);
            }
        }
        int cor=m[maxi];
        if(li[cor]==0)
            mi++;
        else
            ma--;
        v[cor]=-1;
        ans+=maxi;
    }
    cout<<ans;
}
