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