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