#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
int n, q, m, k, l, ans;
vi a, b;
ll lans;
vll la, lb;
string s;
struct Child {
  int i;
  ll v;
  Child(int i, ll v) {
    this->i = i;
    this->v = v;
  }
};
int main() {
  cin >> n;
  vector<Child> childs;
  for (int i = int(0); i < int(n); i++) {
    ll tmp;
    cin >> tmp;
    childs.push_back(Child(i, tmp));
  }
  sort((childs).begin(), (childs).end(),
       [](Child& c1, Child& c2) { return c1.v > c2.v; });
  int dp[n + 1][n + 1];
  dp[0][0] = 0;
  for (int i = int(0); i < int(n); i++) {
    Child c = childs[i];
    dp[i + 1][0] = dp[i][0] + c.v * abs(c.i - i);
    dp[0][i + 1] = dp[0][i] + c.v * abs(n - 1 - i - c.i);
  }
  for (int i = int(1); i < int(n + 1); i++) {
    for (int j = int(1); j < int(n + 1); j++) {
      if (i + j > n) {
        dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
      } else {
        Child c = childs[i + j - 1];
        int left = dp[i - 1][j] + c.v * abs(c.i - (i - 1));
        int right = dp[i][j - 1] + c.v * abs(n - j - c.i);
        dp[i][j] = max(left, right);
      }
    }
  }
  cout << dp[n][n] << endl;
  return 0;
}
