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

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 998244353;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2000 + 10;

ll a[maxn];

unordered_map<pair<int,int>, ll>dp[maxn];

int n;

vector<pair<ll, int>>ord;

ll solve(int pos, int l, int r)
{
  if(pos == n)
    return 0;
  if(dp[pos].count({l, r}))
    return dp[pos][{l,r}];
  dp[pos][{l, r}] = 0;
  ll ans = 0; 

  ans = abs(ord[pos].second - l) * ord[pos].first + solve(pos + 1, l + 1, r);
  ans = max(ans, abs(ord[pos].second - r) * ord[pos].first + solve(pos + 1, l,  r - 1));

  return dp[pos][{l,r}] = ans;
}


int main()
{
  ios::sync_with_stdio(0);
  cin >> n;
  
  for(int i = 1; i <= n ; i++)
  {
    cin >> a[i];
    ord.push_back({a[i], i});
  }

  sort(ord.begin(), ord.end(), greater<pair<ll, int>>());

  cout << solve(0, 1, n) << endl;
  return 0;
} 