#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (int)(N); ++i) cin >> A[i];
  vector<pair<int, int>> indexed(N);
  for (int i = 0; i < (int)(N); ++i) indexed[i] = {A[i], i};
  sort((indexed).begin(), (indexed).end(), greater<pair<int, int>>());
  vector<vector<int64_t>> dp(N + 1, vector<int64_t>(N + 1));
  for (int L = 0; L < (int)(N + 1); ++L)
    for (int R = 0; R < (int)(N - L + 1); ++R) {
      if (L == 0 && R == 0) {
        dp[L][R] = 0;
      } else {
        auto [_, k] = indexed[L + R - 1];
        int64_t vl = L >= 1 ? dp[L - 1][R] + A[k] * abs(k + 1 - L)
                            : numeric_limits<int64_t>::min();
        int64_t vr = R >= 1 ? dp[L][R - 1] + A[k] * abs(k + 1 - (N - R + 1))
                            : numeric_limits<int64_t>::min();
        dp[L][R] = max(vl, vr);
      }
    }
  int64_t ans = numeric_limits<int64_t>::min();
  for (int L = 0; L < (int)(N + 1); ++L) ans = max(ans, dp[L][N - L]);
  cout << ans << '\n';
}
