#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 200005;
long long int dp[2005][2005];
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    v.push_back({x, i});
  }
  sort(v.rbegin(), v.rend());
  for (int i = 1; i <= n; i++) {
    int val = v[i - 1].first, pos = v[i - 1].second;
    for (int j = 0; j < i; j++) {
      int l = j, r = i - 1 - j;
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + val * abs(l + 1 - pos));
      l = i - 1 - j, r = j;
      dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + val * abs(n - r - pos));
    }
  }
  long long int ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[i][n - i]);
  }
  cout << ans << '\n';
}
int main() {
  cin.tie(NULL), cout.sync_with_stdio(true);
  int t = 1;
  while (t--) solve();
  return 0;
}
