#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(A.rbegin(), A.rend());
  for (int i = 0; i < N; i++) {
  }
  vector<vector<int>> dp(N + 1, vector<int>(N + 1));
  for (int l = 0; l < N; l++) {
    dp[0][0] = 0;
    for (int r = 0; r < N; r++) {
      int index = A[l + r].second;
      int agressive = A[l + r].first;
      if (l + r >= N) {
        continue;
      }
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + agressive * abs(index - l));
      dp[l][r + 1] =
          max(dp[l][r + 1], dp[l][r] + agressive * abs((N - 1) - r - index));
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, dp[i][N - i]);
  }
  cout << ans << endl;
}
