#include <bits/stdc++.h>
using namespace std;
int N;
vector<vector<long long>> dp;
vector<pair<int, int>> A;
int main() {
  cin >> N;
  dp.resize(N + 1, vector<long long>(N + 1));
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A.push_back(pair<int, int>(a, i));
  }
  sort(A.begin(), A.end(), greater<pair<int, int>>());
  long long ans = -1;
  for (int l = 0; l < N; ++l) {
    for (int r = 0; r < N; ++r) {
      if (l + r == N) {
        ans = max(ans, dp[l][r]);
        break;
      }
      int activeness = A[l + r].first, idx = A[l + r].second;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + activeness * abs(idx - l));
      dp[l][r + 1] =
          max(dp[l][r + 1], dp[l][r] + activeness * abs(idx - N + r + 1));
    }
  }
  cout << ans << endl;
}
