#include <bits/stdc++.h>
using namespace std;
long long a[2005];
long long dp[2005][2005];
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  for (int i = 1; i < (n + 1); ++i) {
    int t;
    cin >> t;
    v.push_back({t, i});
  }
  sort(begin(v), end(v));
  reverse(begin(v), end(v));
  for (int sum = 0; sum < n; sum++) {
    int act = v[sum].first, pos = v[sum].second;
    for (int i = 0; i <= sum; i++) {
      int j = sum - i;
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + act * abs((i + 1) - pos));
      dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + act * abs((n - j) - pos));
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
}
