#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e18;
const long long MAX = 2002;
long long store[MAX][MAX];
vector<pair<long long, long long> > vec;
long long dp(int idx, int l, int r) {
  if (l > r) return -1;
  long long &ans = store[l][r];
  if (ans != -1) return ans;
  long long present = abs(idx - l) * vec[idx].first + dp(idx + 1, l + 1, r);
  present = max(present, abs(r - vec[idx].second) * vec[idx].first +
                             dp(idx + 1, l, r - 1));
  store[l][r] = present;
  return present;
}
void solve() {
  long long n;
  cin >> n;
  vec.resize(n);
  memset(store, -1, sizeof(store));
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first;
    vec[i].second = i;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  cout << dp(0, 0, n - 1);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
