#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
const int inf = 0x7ffffff;
long long dp[maxn][maxn];
void solve() {
  int N;
  cin >> N;
  vector<pair<int, int>> vec(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec[i].first;
    vec[i].second = i + 1;
  }
  sort(vec.rbegin(), vec.rend());
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      int l = j + 1, r = N - i + j;
      if (r + 1 <= N)
        dp[l][r] =
            max(dp[l][r], dp[l][r + 1] + vec[i - 1].first *
                                             abs(vec[i - 1].second - r - 1));
      if (l - 1 >= 1)
        dp[l][r] =
            max(dp[l][r], dp[l - 1][r] + vec[i - 1].first *
                                             abs(vec[i - 1].second - l + 1));
    }
  }
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans = max(ans, dp[i][i] + vec[N - 1].first * abs(i - vec[N - 1].second));
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1;
  while (T-- > 0) solve();
}
