#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, int>;
long long dp[2020][2020];
int main(void) {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<P> p(n);
  for (int i = 0; i < int(n); ++i) {
    cin >> a[i];
    p[i] = {a[i], i};
  }
  sort((p).begin(), (p).end(), greater<P>());
  for (int i = 0; i < int(n); ++i) {
    int pos = p[i].second;
    for (int l = 0; l < int(i + 1); ++l) {
      int r = i - l;
      if (l < n) {
        dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + a[pos] * abs(l - pos));
      }
      if (r < n) {
        dp[l][r + 1] =
            max(dp[l][r + 1], dp[l][r] + a[pos] * abs(n - 1 - r - pos));
      }
    }
  }
  long long res = 0;
  for (int l = 0; l < int(n + 1); ++l) {
    int r = n - l;
    res = max(dp[l][r], res);
  }
  cout << res << endl;
  return 0;
}
