#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;
ll dp[2010][2010];
ll f2(ll l, ll r, ll n, vector<pair<ll, ll>> &a) {
  if (l > r) return 0;
  if (dp[l][r] >= 0) return dp[l][r];
  ll ind = l + (n - 1 - r);
  ll ans1 = (a[ind].first * (a[ind].second - l)) + f2(l + 1, r, n, a);
  ll ans2 = (a[ind].first * (r - a[ind].second)) + f2(l, r - 1, n, a);
  return dp[l][r] = max(0LL, max(ans1, ans2));
}
void solve() {
  ll n;
  cin >> n;
  vector<pair<ll, ll>> a;
  for (ll i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    a.push_back(make_pair(x, i));
  }
  memset(dp, 0, sizeof(dp));
  sort(a.rbegin(), a.rend());
  for (int l = 0; l < n; ++l) {
    for (int r = n - 1; r >= l; --r) {
      int ind = l + (n - 1 - r);
      int val = a[ind].first;
      int pos = a[ind].second;
      ll d1 = val * abs(pos - l);
      ll d2 = val * abs(pos - r);
      dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + d1);
      if (r - 1 >= 0) dp[l][r - 1] = max(dp[l][r - 1], dp[l][r] + d2);
    }
  }
  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
