#include <bits/stdc++.h>
using namespace std;
int const N = 2001;
int n, v[N];
long long dp[N][N];
vector<pair<int, int> > x;
bool srt(pair<int, int> a, pair<int, int> b) {
  if (a.first > b.first) return true;
  return a.first == b.first ? a.second < b.second : 0;
}
long long go(int cur, int l, int r) {
  if (l > r) return 0;
  long long &ret = dp[l][r];
  if (ret + 1) return ret;
  ret = go(cur + 1, l + 1, r) + (x[cur].first * abs(l - x[cur].second));
  ret =
      max(ret, go(cur + 1, l, r - 1) + (x[cur].first * abs(r - x[cur].second)));
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", v + i);
    x.push_back({v[i], i});
  }
  memset(dp, -1, sizeof dp);
  long long an = go(0, 0, n - 1);
  sort(x.begin(), x.end(), srt);
  printf("%lld\n", an);
}
