#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
  preprocess() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} ____;
ll dp[2005][2005];
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.rbegin(), a.rend());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ll left = 0;
      ll right = 0;
      if (i > 0 & i - 1 + j < n)
        left = dp[i - 1][j] +
               max((a[i - 1 + j].second - (i - 1)) * a[i - 1 + j].first, 0);
      if (j > 0 & i - 1 + j < n)
        right = dp[i][j - 1] + max((n - 1 - (j - 1) - a[i - 1 + j].second) *
                                       a[i - 1 + j].first,
                                   0);
      dp[i][j] = max(left, right);
    }
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << '\n';
}
