/*
              ██████  ██████
              ██   ██ ██   ██
 Author ->    ██████  ██   ██
              ██      ██   ██
              ██      ██████
 
  nik is love.
  nik is motivation.
  Ek modulus aapki jindagi barbaad kar sakti hai
  Watch for integer overflows.
  A dream doesn't become reality through magic; it takes sweat, determination and hard work" — Colin Powell
 */
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional>
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define eps                   0.000000001
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define present(c,x)         ((c).find(x) != (c).end())
#define cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair<ll,ll>
#define endl                 '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> special_map;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
const ll inf=1000000009;
//vector<ll> vis(200010,0),par(200010,0),dis(200010,inf),di(200010,0),fin(200010,0);
//vector<ll> adj[200010];
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}

#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}

inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }

template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
int myrandom (int i) { return std::rand()%i;}
const int MAX=100010;
using namespace std;
ll dp[2010][2010];
ll solve(vector<pair<ll,ll>> &pos,int id,int l,int r)
{
    if(dp[l][r]!=-1)
    {
        return dp[l][r];
    }
    if(id==(int)pos.size())
    {
        return dp[l][r]=0;
    }
    ll maxi1=solve(pos,id+1,l+1,r);
    ll maxi2=solve(pos,id+1,l,r-1);
    dp[l][r]=max(maxi1+abs(pos[id].ss-l)*pos[id].ff,maxi2+abs(pos[id].ss-r)*pos[id].ff);
    return dp[l][r];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    //clock_t launch=clock();
    ll n;
    cin>>n;
    vector<pair<ll,ll>> pos;
    rep(i,0,n)
    {
        int a;
        cin>>a;
        pos.pb({a,i+1});
    }
    sort(all(pos),greater<pair<ll,ll>>());
    memset(dp,-1,sizeof(dp));
    cout<<solve(pos,0,1,n)<<endl;
    //clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}



Measured memory_bytes: 35488