#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e5 + 5, MOD = 1e9;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long mod = 1e9 + 7;
long long fastpowMOD(long long a, long long p, long long MOD) {
  if (p == 0) return 1;
  long long z = fastpowMOD(a, p / 2, MOD);
  z = (z * z) % MOD;
  if (p % 2) z = (z * a) % MOD;
  return z;
}
long long fact[200004];
void compfact() {
  fact[0] = 1;
  for (long long i = 1; i <= 200002; i++)
    fact[i] = (fact[i - 1] % mod * i % mod) % mod;
}
vector<pair<long long, long long> > v;
long long dp[2002][2002];
void solve(long long ind, long long l, long long r) {
  if (ind < 0 || ind >= v.size()) return;
  if (dp[l][r] != -1)
    return;
  else if (l > r)
    return;
  else if (l == r) {
    dp[l][r] = v[ind].first * abs(v[ind].second - l);
  } else {
    solve(ind + 1, l + 1, r);
    solve(ind + 1, l, r - 1);
    dp[l][r] =
        max(dp[l][r], dp[l + 1][r] + v[ind].first * abs(v[ind].second - l));
    dp[l][r] =
        max(dp[l][r], dp[l][r - 1] + v[ind].first * abs(v[ind].second - r));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    v.push_back({x, i});
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      dp[i][j] = -1;
    }
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  solve(0, 1, n);
  cout << dp[1][n];
}
