#include <bits/stdc++.h>
using namespace std;
const long long SIZE = 1e5 * 2 + 10, INF = 1e9 * 1e9 + 10, MOD = 1e9 + 7;
long long dp[2005][2005];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long n;
  cin >> n;
  vector<long long> vec(n);
  vector<pair<long long, long long>> vec2;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
    vec2.push_back({vec[i], i});
  }
  sort(vec2.rbegin(), vec2.rend());
  for (int i = 0; i < n; i++) {
    long long vl = vec2[i].first, pos = vec2[i].second;
    for (int j = 0; j < n; j++) {
      if (i >= j) {
        dp[i + 1][j + 1] =
            max(dp[i + 1][j + 1], dp[i][j] + (vl * abs(pos - j)));
      }
      long long tp = i - j;
      if (tp >= 0 && i <= n - tp - 1) {
        dp[i + 1][j] =
            max(dp[i + 1][j], dp[i][j] + (vl * abs(abs(n - tp - 1) - pos)));
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
  return 0;
}
