#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mo = 1e9 + 7;
constexpr int inf = 1 << 30;
constexpr ll infl = 1ll << 60;
constexpr ll mo2 = 998244353;
const double PAI = acos(-1);
constexpr long double eps = 1e-9;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v[i] = {a, i};
  }
  sort(v.rbegin(), v.rend());
  vector<vector<ll>> dp(2050, vector<ll>(2050, -inf));
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i)
    for (int x = 0; x <= i; ++x) {
      int y = i - x;
      dp[x + 1][y] =
          max(dp[x + 1][y], dp[x][y] + v[i].first * abs(v[i].second - x));
      dp[x][y + 1] = max(dp[x][y + 1],
                         dp[x][y] + v[i].first * abs(n - y - 1 - v[i].second));
    }
  ll ret = -inf;
  for (int i = 0; i <= n; ++i) {
    ret = max(ret, dp[i][n - i]);
  }
  cout << ret << endl;
  return 0;
}
