#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long A[n];
  for (int i = 0; i < n; i++) cin >> A[i];
  vector<pair<int, int> > x;
  for (int i = 0; i < n; i++) x.push_back({A[i], i});
  sort(x.rbegin(), x.rend());
  long long dp[2][n + 1];
  int cur = 0, prev = 1;
  dp[prev][0] = 0;
  for (int k = 0; k < n; k++) {
    auto p = x[k];
    for (int i = 0; i <= k + 1; i++) {
      int j = n - 1 - k + i;
      long long v = 0;
      if (i > 0)
        v = max(v, dp[prev][i - 1] + p.first * abs(p.second - (i - 1)));
      if (i <= k) v = max(v, dp[prev][i] + p.first * abs(p.second - j));
      dp[cur][i] = v;
    }
    swap(cur, prev);
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, dp[prev][i]);
  cout << ans << endl;
}
