#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
long long dp[N][N], n, k;
vector<pair<int, int> > v;
long long solve(int l, int r) {
  if (r < l) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  int i = l + n - r - 1;
  return dp[l][r] = max(v[i].first * abs(v[i].second - l) + solve(l + 1, r),
                        v[i].first * abs(v[i].second - r) + solve(l, r - 1));
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    v.push_back({k, i});
  }
  sort(v.rbegin(), v.rend());
  memset(dp, -1, sizeof(dp));
  cout << solve(0, n - 1);
  return 0;
}
