#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll dp[2005][2005];
int main() {
  int n;
  cin >> n;
  P a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a, a + n, greater<P>());
  ll ans = 0;
  for (int l = 0; l < n; l++) {
    for (int r = 0; r < n; r++) {
      if (l + r == n) {
        ans = max(ans, dp[l][r]);
        break;
      }
      dp[l + 1][r] = max(dp[l + 1][r],
                         dp[l][r] + a[l + r].first * abs(a[l + r].second - l));
      dp[l][r + 1] =
          max(dp[l][r + 1],
              dp[l][r] + a[l + r].first * abs(a[l + r].second - (n - 1 - r)));
    }
  }
  cout << ans << endl;
}
