#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  return b ? gcd(b, a % b) : a;
}
unsigned long long lcm(unsigned long long a, unsigned long long b) {
  return a / gcd(a, b) * b;
}
int main() {
  int n;
  cin >> n;
  vector<pii> a(n);
  for (int i = 0, i_len = (n); i < i_len; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort((a).rbegin(), (a).rend());
  vector<vector<ll> > dp(n + 1, vector<ll>(n + 1, 0));
  for (int i = 0, i_len = (n + 1); i < i_len; i++)
    for (int j = 0, j_len = (n + 1 - i); j < j_len; j++) {
      if (i == 0 && j == 0) continue;
      int na = a[i + j - 1].first, np = a[i + j - 1].second;
      ll u = (i > 0) ? dp[i - 1][j] : 0, l = (j > 0) ? dp[i][j - 1] : 0;
      if (i > 0) u += na * abs(np - (n - i));
      if (j > 0) l += na * abs(np - (j - 1));
      dp[i][j] = max(u, l);
    }
  ll ans = 0;
  for (int i = 0, i_len = (n + 1); i < i_len; i++) ans = max(ans, dp[i][n - i]);
  cout << ans << endl;
  return 0;
}
