#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> A(n);
  for (int i=0; i<n; i++) {
    int a;
    cin >> a;
    A[i] = make_pair(a, i);
  }

  sort(A.begin(), A.end(), greater<pair<int, int>>());

  ll dp[n+1][n+1];
  for (int i=0; i<=n; i++) {
    for (int j=0; j<=n; j++) dp[i][j] = 0;
  }

  for (int i=0; i<n; i++) {
    ll v = (ll)A[i].first;
    int x = A[i].second;
    for (int j=0; j<=i; j++) {
      dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j] + v * abs(x - j));
      dp[j][i-j+1] = max(dp[j][i-j+1], dp[j][i-j] + v * abs(x - (n-i+j-1)));
    }
  }
  ll ans = 0;
  for (int i=0; i<=n; i++) {
    ans = max(ans, dp[i][n-i]);
  }
  cout << ans << endl;
  return 0;
}