#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> vec(n);
    for(ll i=0;i<n;++i)
    {
        cin>>vec[i];
    }
    ll lo=0,hi=n-1;
    set<ll> s;
    ll sum=0;
    for(ll j=0;j<n;++j)
    {
        ll max=INT_MIN;
        ll temp;
        for(ll i=0;i<n;++i)
        {
            if(s.find(i)==s.end())
            {
                ll temp1=vec[i]*abs(hi-i);
                ll temp2=vec[i]*abs(lo-i);
                if(temp1>temp2)
                {
                    if(temp1>max)
                    {
                        max=temp1;
                        temp=i;
                    }
    
                }
                else
                {
                     if(temp2>max)
                        {
                            max=temp2;
                            temp=i;
                        }
                }
            }
        }
        sum+=max;
        s.insert(temp);
        if(abs(hi-temp)>abs(lo-temp))
        {
            hi--;
            hi=std::max(0,hi);
        }
        else
        {
            lo++;
            lo=std::min(n-1,lo);
        }
    }
    cout<<sum<<"\n";

}
