#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<P> a;
  for (int i = 0; i < n; ++i) {
    int ai;
    cin >> ai;
    a.emplace_back(ai, i);
  }
  sort(a.rbegin(), a.rend());
  vector<ll> dp(n + 1);
  for (int i = 0; i < n; ++i) {
    vector<ll> temp(n + 1);
    for (int l = 0; l < i + 1; ++l) {
      int r = i - l;
      temp[l + 1] = max(temp[l + 1], dp[l] + a[i].first * (a[i].second - l));
      temp[l] = max(temp[l], dp[l] + a[i].first * (n - r - 1 - a[i].second));
    }
    swap(dp, temp);
  }
  ll ans = 0;
  for (int i = 0; i < n + 1; ++i) ans = max(ans, dp[i]);
  cout << ans << endl;
}
