#include <bits/stdc++.h>
using namespace std;
using int32 = int_fast32_t;
using int64 = int_fast64_t;
const int32 INF = 1e9;
const int32 MOD = 1e9 + 7;
const int64 LLINF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  vector<pair<int32, int32>> a(n);
  for (int64 i = 0; i < (n); ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  vector<vector<int64>> dp(n + 1, vector<int64>(n + 1, -LLINF));
  dp[0][0] = 0;
  for (int64 i = 0; i < (n); ++i) {
    for (int64 j = 0; j < (n); ++j) {
      if (i + j >= n) continue;
      dp[i + 1][j] = max(dp[i + 1][j],
                         dp[i][j] + a[i + j].first * abs(i - a[i + j].second));
      dp[i][j + 1] =
          max(dp[i][j + 1],
              dp[i][j] + a[i + j].first * abs(n - 1 - j - a[i + j].second));
    }
  }
  int64 ans = 0;
  for (int64 i = 0; i < (n + 1); ++i) ans = max(ans, dp[i][n - i]);
  cout << (ans) << "\n";
  return 0;
}
