// Reading stuff 
// check the modulus 
// for tree case n=1


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
#include <bits/stdc++.h>
#include <vector> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)
const ll hell=1000000007;


int solve(){    
 
int n;
cin>>n;
set<int> st ;
vi a(n);
rep(i,0,n)cin>>a[i];
bool bl[n]={false};
rep(i,0,n)st.insert(i);
int ans=0;

rep(l,0,n)
{ 
  int pos=0,mx=0;
  set<int> :: iterator it=st.begin(),it1=st.end();
  it1--;
  rep(i,0,n)
  {
    if(bl[i])continue;
    int x1=abs(i-*it),x2=abs(i-*it1);
    x1*=a[i],x2*=a[i];
    x1=max(x1,x2);
    if(mx<x1)
    {
      mx=x1;
      pos=i;
    }
  }
  bl[pos]=true;
  ans+=mx;
  if(abs(*it-pos)>=abs(*it1-pos))st.erase(it);
  else st.erase(it1);
}
cout<<ans;


return 0;
}

 
signed main()
{    


   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);


int t=1;                                                                                                                  
//cin>>t;
int k=1;

    while(t--)
     {
      //cout<<"Case #"<<k<<": ";
      k++;
      solve();
     }
    return 0;
  }