#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll dp[2010][2010];
int main() {
  int n;
  cin >> n;
  vector<pli> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < n + 1; i++)
    for (int j = 0; j < n + 1; j++) dp[i][j] = -LLINF;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      chmax(dp[i + 1][j + 1], dp[i][j] + a[i].first * abs(a[i].second - j));
      chmax(dp[i + 1][j],
            dp[i][j] + a[i].first * abs(a[i].second - (n - i + j - 1)));
    }
  }
  ll ans = 0;
  for (int i = 0; i < n + 1; i++) chmax(ans, dp[n][i]);
  cout << ans << endl;
}
