#include <bits/stdc++.h>
using namespace std;
int n;
int a[2005];
int v[2005];
long long dp[2005][2005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  iota(v, v + 1 + n, 0);
  sort(v + 1, v + 1 + n,
       [](const int &i, const int &j) { return a[i] > a[j]; });
  memset(dp, 0xC0, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j > 0)
        dp[i][j] = max(dp[i][j],
                       dp[i - 1][j - 1] + (long long)abs(v[i] - j) * a[v[i]]);
      if (i > j)
        dp[i][j] =
            max(dp[i][j], dp[i - 1][j] +
                              (long long)abs(v[i] - (n - i + j + 1)) * a[v[i]]);
    }
  }
  cerr << *max_element(dp[n], dp[n] + 1 + n) << endl;
  return 0;
}
