#include <bits/stdc++.h>
using namespace std;
long long n;
long long dp[2005][2005];
long long suri(long long idx, long long iav,
               vector<pair<long long, long long>> &v) {
  if (idx == n) return 0;
  if (dp[idx][iav] != -1) return dp[idx][iav];
  long long ans =
      (abs(iav - v[idx].second) * v[idx].first) + suri(idx + 1, iav + 1, v);
  long long jav = n - 1 - (idx - iav);
  ans = max(ans,
            (abs(jav - v[idx].second) * v[idx].first) + suri(idx + 1, iav, v));
  dp[idx][iav] = ans;
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T = 1;
  while (T--) {
    long long i, j;
    cin >> n;
    vector<pair<long long, long long>> v(n);
    for (i = 0; i < n; i++) {
      cin >> v[i].first;
      v[i].second = i;
    }
    memset(dp, -1, sizeof dp);
    sort((v).begin(), (v).end(), greater<pair<long long, long long>>());
    cout << suri(0, 0, v) << "\n";
  }
  return 0;
}
