#include <bits/stdc++.h>
using namespace std;
int cases = 1;
const int N = 2e3 + 3;
vector<pair<int, int> > v;
int dp[N][N];
long long rec(long long pos, long long lft, long long rgt) {
  if (lft > rgt) return 0;
  if (dp[lft][rgt] != -1) return dp[lft][rgt];
  long long l =
      abs(lft - v[pos].second) * v[pos].first + rec(pos + 1, lft + 1, rgt);
  long long r =
      abs(rgt - v[pos].second) * v[pos].first + rec(pos + 1, lft, rgt - 1);
  return dp[lft][rgt] = max(l, r);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    v.push_back(make_pair(c, i));
  }
  sort(v.rbegin(), v.rend());
  cout << rec(0, 0, n - 1);
}
