#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<pair<int, int>> q(n);
  for (int i = 0; i < n; i++) {
    q[i] = {a[i], i};
  }
  sort(q.rbegin(), q.rend());
  vector<vector<long long int>> d(n + 1,
                                  vector<long long int>(n + 1, LLONG_MIN));
  d[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (d[i][j] == LLONG_MIN) continue;
      {
        d[i + 1][j + 1] =
            max(d[i + 1][j + 1],
                d[i][j] + (long long int)q[i].first * abs(q[i].second - j));
      }
      {
        d[i + 1][j] = max(d[i + 1][j],
                          d[i][j] + (long long int)q[i].first *
                                        abs(q[i].second - (n - 1 - (i - j))));
      }
    }
  }
  long long int res = 0;
  for (int j = 0; j < n; j++) {
    res = max(res, d[n][j]);
  }
  return 0;
}
