#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long ll_inf = 1e18 + 7;
const int K = 2e5;
const int N = 2e5 + 300;
long long binpow(long long a, long long n) {
  if (n == 0) return 1ll;
  long long res = 1;
  while (n) {
    if (n & 1) {
      res *= a;
      res %= inf;
    }
    a *= a;
    n >>= 1;
    a %= inf;
  }
  return res;
}
void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int dp[2020][2020];
int n;
pair<int, int> a[2020];
int rec(int l, int r, int v) {
  if (l == r) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  dp[l][r] = max(rec(l + 1, r, v - 1) + abs(l - a[v].second) * a[v].first,
                 rec(l, r - 1, v - 1) + abs(r - 1 - a[v].second) * a[v].first);
  return dp[l][r];
}
int main() {
  cin >> n;
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= n + 1; ++j) dp[i][j] = -1;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a, a + n);
  cout << rec(0, n, n - 1);
}
