#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int MOD = 1000000007;
struct Swap {
  ll v;
  int x;
  int y;
};
int main() {
  ll n, a;
  cin >> n;
  vector<pll> v;
  for (ll i = 0; i < n; ++i) {
    cin >> a;
    v.emplace_back(make_pair(a, i));
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INT_MIN));
  dp[0][0] = 0;
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i <= k + 1; ++i) {
      int j = k - i + 1;
      ll A = v[k].first;
      ll i0 = v[k].second;
      if (i - 1 >= 0)
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + A * abs(i - 1 - i0));
      if (j - 1 >= 0)
        dp[i][j] = max(dp[i][j], dp[i][j - 1] + A * abs(n - j - i0));
    }
  }
  ll ans = 0;
  for (ll i = 0; i <= n; ++i) {
    ll j = n - i;
    ans = max(ans, dp[i][j]);
  }
  cout << ans << endl;
  return 0;
}
