#include <bits/stdc++.h>
using namespace std;
int fact[200005];
int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res *= a;
      res %= 1000000007;
    }
    a *= a;
    a %= 1000000007;
    b /= 2;
  }
  return res;
}
int add(int a, int b) { return (0LL + a + b) % 1000000007; }
int sub(int a, int b) { return add(a, 1000000007 - b); }
int mul(int a, int b) { return (1LL * a * b) % 1000000007; }
int inv(int x) { return power(x, 1000000007 - 2); }
int nCr(int n, int r) { return mul(fact[n], inv(mul(fact[r], fact[n - r]))); }
int cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    v.push_back({x, i});
  }
  sort(v.begin(), v.end(), cmp);
  int dp[n + 1][n + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < i; j++) {
      dp[i][j + 1] =
          max(dp[i][j + 1],
              dp[i - 1][j] + v[i - 1].first * abs(v[i - 1].second - (j + 1)));
      dp[i][j] =
          max(dp[i][j], dp[i - 1][j] + v[i - 1].first * abs(v[i - 1].second -
                                                            (n - (i - 1 - j))));
    }
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    mx = max(mx, dp[n][i]);
  }
  cout << mx << "\n";
  return 0;
}
