#include <bits/stdc++.h>
using namespace std;
struct piii {
  long long first, second, th;
  bool operator<(const piii &b) {
    if (first != b.first) return first < b.first;
    if (second != b.second) return second < b.second;
    return th < b.th;
  }
};
long long val, n;
pair<long long, long long> a[2002];
long long f[2002][2002];
bool cmp(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  return a.first > b.first;
}
int main() {
  cout << setprecision(2) << fixed;
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> val;
    a[i] = pair<long long, long long>({val, i});
  }
  sort(a + 1, a + 1 + n, cmp);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      f[i][j] = -1e18;
      if (j > 0)
        f[i][j] =
            max(f[i][j], f[i - 1][j - 1] + a[i].first * abs(a[i].second - j));
      if (j < i)
        f[i][j] =
            max(f[i][j], f[i - 1][j] +
                             a[i].first * abs(a[i].second - (n + 1 - (i - j))));
    }
  }
  long long res = 0;
  for (int i = 0; i <= n; i++) res = max(res, f[n][i]);
  cout << res;
  return 0;
}
