#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (int i = 0; i < n; i++) {
    long long h;
    cin >> h;
    a[i] = make_pair(h, i);
  }
  sort((a).begin(), (a).end());
  reverse((a).begin(), (a).end());
  vector<vector<long long> > dp(n + 1, vector<long long>(n + 1, -(1LL << 50)));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int right = i - j + 1;
      dp[i + 1][j + 1] =
          max(dp[i + 1][j + 1], dp[i][j] + a[i].first * abs(a[i].second - j));
      dp[i + 1][j] = max(dp[i + 1][j],
                         dp[i][j] + a[i].first * abs(n - right - a[i].second));
    }
  }
  long long ans = -1;
  for (int i = 0; i < n + 1; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << '\n';
  return 0;
}
