/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    cin>>n;
    int a[n],b[n]={0};
    int i,j,k,l=1,r=n,x,y,z;
    ll sum,mx=0,ans=0;
    bool f,t;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++) {
        mx=0;
        for(j=0;j<n;j++) {
            if(b[j]==1) continue;
            x=abs(j+1-l);
            y=abs(r-j-1);
            if(x>y) {
                z=x;
                f=true;
            }
            else {
                z=y;
                f=false;
            }
            sum=a[j]*z;
            if(sum>mx) {
                mx=sum;
                k=j;
                t=f;
            }
            else if(sum==mx) {
                if (a[j]<a[k]) {
                    k=j;
                    t=f;
                }
            }
        }
        b[k]=1;
        if(t) l++;
        else r--;
        ans+=mx;
    }
    cout<<ans<<endl;
    return 0;
}
