#include <bits/stdc++.h>
using namespace std;
int main() {
  size_t N;
  cin >> N;
  vector<pair<int, int>> a(N + 1);
  vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
  for (size_t i = 1; i <= N; ++i) {
    cin >> a[i].first;
    a[i].second = (int)i;
  }
  sort(a.begin() + 1, a.end(), greater<pair<int, int>>());
  for (size_t i = 1; i <= N; ++i) {
    for (size_t j = 0; j < i; ++j) {
      auto l = j;
      auto r = i - 1 - j;
      dp[l + 1][r] = max(dp[l + 1][r],
                         dp[l][r] + a[i].first * abs((int)l + 1 - a[i].second));
      dp[r][l + 1] =
          max(dp[r][l + 1],
              dp[r][l] + a[i].first * abs((int)N - (int)l - a[i].second));
    }
  }
  int res = 0;
  for (size_t i = 1; i <= N; ++i) {
    res = max(res, dp[i][N - i]);
  }
  cout << res;
  return 0;
}
