#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template <typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;
int main() {
  int n;
  cin >> n;
  vl a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  vi idx(n);
  iota((idx).begin(), (idx).end(), 0);
  sort((idx).begin(), (idx).end(), [&](int &l, int &r) { return a[l] > a[r]; });
  vl dp(n + 1, 0);
  for (int i = 0; i < (n); i++) {
    vl ndp(n, 0);
    for (int j = 0; j < (i + 1); j++) {
      ndp[j + 1] = max(ndp[j + 1], dp[j] + a[idx[i]] * abs(j - idx[i]));
      ndp[j] = max(ndp[j], dp[j] + a[idx[i]] * abs(n - 1 - (i - j) - idx[i]));
    }
    dp = ndp;
  }
  ll ans = 0;
  for (int i = 0; i < (n + 1); i++) {
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}
