#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort((a).rbegin(), (a).rend());
  vvll dp(n + 1, vll(n, 0LL));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < i + 1; ++j) {
      dp[i + 1][j] =
          max(dp[i + 1][j],
              dp[i][j] + a[i].first * abs(n - 1 - (i - j) - a[i].second));
      dp[i + 1][j + 1] =
          max(dp[i + 1][j + 1], dp[i][j] + a[i].first * abs(a[i].second - j));
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans << endl;
  return 0;
}
