#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (i = 0; i < n; ++i) {
    cin >> a.at(i);
  }
  vector<pair<ll, ll>> b;
  for (i = 0; i < n; ++i) {
    b.emplace_back(a.at(i), i);
  }
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  vector<vector<ll>> dp(n, vector<ll>(n + 1, 0));
  dp.at(0).at(0) = b.front().first * (n - 1 - b.front().second);
  dp.at(0).at(1) = b.front().first * b.front().second;
  for (i = 1; i < n; ++i) {
    auto x = b.at(i);
    ll val = x.first;
    ll ind = x.second;
    for (j = 0; j < i + 1; ++j) {
      if (j == 0) {
        dp.at(i).at(j) = dp.at(i - 1).at(j) + val * abs(n - i - 1 - ind);
      } else {
        dp.at(i).at(j) =
            max(dp.at(i - 1).at(j) + val * abs(n - i + j - 1 - ind),
                dp.at(i - 1).at(j - 1) + val * abs(ind - j + 1));
      }
    }
  }
  ll ans = 0;
  for (i = 0; i <= n; ++i) {
    ans = max(ans, dp.at(n - 1).at(i));
  }
  cout << ans << endl;
  return 0;
}
