#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const long long inf = 1e16;
long long dp[N], ndp[N];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<array<int, 2> > v(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    v[i] = array<int, 2>{a[i], i};
  }
  sort(v.rbegin(), v.rend());
  fill(dp, dp + N, -inf);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    fill(ndp, ndp + N, -inf);
    int cur = v[i][1];
    for (int lft = 0; lft < n + 1; ++lft) {
      int ltar = lft;
      long long lgain = a[cur] * abs(ltar - cur);
      ndp[lft + 1] = max(ndp[lft + 1], dp[lft] + lgain);
      int rtar = n - 1 - (i - lft);
      long long rgain = a[cur] * abs(rtar - cur);
      ndp[lft] = max(ndp[lft], dp[lft] + rgain);
    }
    swap(dp, ndp);
  }
  long long ans = *max_element(dp, dp + n + 2);
  cout << ans << '\n';
}
