#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 2005;
ll dp[N][N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  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 + 1;
  }
  sort(a.rbegin(), a.rend());
  for (int i = 0; i < n; i++) {
    for (int pref = 0; pref <= i + 1; pref++) {
      if (pref) {
        dp[i + 1][pref] =
            dp[i][pref - 1] + a[i].first * abs(a[i].second - pref);
      }
      if (pref < i + 1) {
        dp[i + 1][pref] =
            max(dp[i + 1][pref],
                dp[i][pref] + a[i].first * abs(n - i + pref - a[i].second));
      }
    }
  }
  cout << *max_element(dp[n], dp[n] + n + 1) << endl;
  return 0;
}
