#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > v;
long long dp[2007][2007];
long long solve(int l, int r) {
  if (dp[l][r] != -1) return dp[l][r];
  long long atual = v[l + n - r - 1].first;
  int idx = v[l + n - r - 1].second;
  if (l == r) {
    return atual * abs(idx - l);
  }
  long long a1 = solve(l + 1, r) + atual * abs(idx - l);
  long long a2 = solve(l, r - 1) + atual * abs(idx - r);
  return dp[l][r] = max(a1, a2);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  v.resize(n);
  for (int i = 0; i < (int)n; i++) cin >> v[i].first, v[i].second = i;
  sort(v.rbegin(), v.rend());
  cout << solve(0, n - 1) << '\n';
  return 0;
}
