#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << H << " ";
  debug_out(T...);
}
constexpr int max_n = 2000 + 5;
int n;
vector<pair<int, int>> as;
vector<vector<long long>> dp(max_n, vector<long long>(max_n));
long long res;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(15);
  cin >> n;
  as.resize(n);
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    as[i] = {a, i};
  }
  sort(as.rbegin(), as.rend());
  dp[0][n] = 0;
  for (int l = n - 1; l >= 0; l--) {
    for (int i = 0, j = l; j <= n; i++, j++) {
      int k = n - l - 1;
      int a = as[k].first, pos = as[k].second;
      dp[i][j] = 0;
      if (i - 1 >= 0) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + a * abs(i - 1 - pos));
      }
      if (j + 1 <= n) {
        dp[i][j] = max(dp[i][j], dp[i][j + 1] + a * abs(j - pos));
      };
    }
  }
  for (int i = 0; i < (int)(n + 1); i++) {
    res = max(res, dp[i][i]);
  }
  cout << res << '\n';
  return 0;
}
