#include <bits/stdc++.h>
using namespace std;
using P = pair<long, long>;
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> a;
  long long i, j;
  for (i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    a.push_back({tmp, i});
  }
  sort(a.begin(), a.end(), greater<pair<long long, long long>>());
  long long dp[2020][2020];
  dp[0][0] = 0;
  dp[1][0] = a[0].first * abs(0 - a[0].second);
  dp[0][1] = a[0].first * abs(n - 1 - a[0].second);
  for (i = 1; i <= n; i++) {
    for (j = 1; i + j <= n; j++) {
      dp[i][j] = max(
          dp[i - 1][j] + a[i + j - 1].first * abs(i - 1 - a[i + j - 1].second),
          dp[i][j - 1] + a[i + j - 1].first * abs(n - j - a[i + j - 1].second));
    }
  }
  long long ans = 0;
  for (i = 0; i <= n; i++) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << endl;
}
