#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18L + 1;
const int INF = 1e9 + 1;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); ++i) cin >> A[i];
  vector<pair<int, int>> ord(N);
  for (int i = 0; i < (N); ++i) ord[i] = pair<int, int>(i, A[i]);
  sort(ord.begin(), ord.end(),
       [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });
  vector<vector<long long>> dp(N + 1, vector<long long>(N + 1, 0));
  long long ans = 0;
  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 idx = l + r;
      dp[l + 1][r] = max(dp[l + 1][r],
                         dp[l][r] + ord[idx].second * abs(ord[idx].first - l));
      dp[l][1 + r] =
          max(dp[l][r + 1],
              dp[l][r] + ord[idx].second * abs((N - 1 - r) - ord[idx].first));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
