#include <bits/stdc++.h>
using namespace std;
long long int dp[2005][2005];
bool comp(pair<long long int, long long int> a,
          pair<long long int, long long int> b) {
  return a.first > b.first;
}
void solve() {
  long long int n;
  cin >> n;
  vector<pair<long long int, long long int> > v(n);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i].first;
    v[i].second = i;
  }
  sort(v.begin(), v.end(), comp);
  for (long long int i = 0; i < n; i++) {
    for (long long int l = 0; l <= i; l++) {
      dp[l + 1][i - l] = max(dp[l + 1][i - l],
                             dp[l][i - l] + v[i].first * abs(v[i].second - l));
      dp[l][i - l + 1] =
          max(dp[l][i - l + 1],
              dp[l][i - l] + v[i].first * abs(n - i + l - 1 - v[i].second));
    }
  }
  long long int res = 0;
  for (long long int i = 0; i <= n; i++) res = max(res, dp[i][n - i]);
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int qc = 1;
  for (long long int i = 1; i <= qc; i++) solve();
}
