#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end(), greater<pair<int, int> >());
  long long dp[n + 1][n + 1];
  dp[0][n] = 0;
  for (int i = 0; i < n; i++) {
    int act = a[i].first;
    int pos = a[i].second;
    dp[0][n - 1 - i] = dp[0][n - i] + act * abs(n - 1 - i - pos);
    dp[i + 1][n] = dp[i][n] + act * abs(pos - i);
    for (int j = 1; j < i + 1; j++) {
      int k = n - i - 1 + j;
      dp[j][k] = max(dp[j][k + 1] + act * abs(k - pos),
                     dp[j - 1][k] + act * abs(pos - j + 1));
    }
  }
  long long ma = 0;
  for (int i = 0; i <= n; i++) ma = max(ma, dp[i][i]);
  cout << ma << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
