#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v;
long long n;
long long dp[2009][2009];
long long call(long long ind, long long pre) {
  if (ind == v.size()) return 0;
  long long ses = n - 1 - (ind - pre);
  long long &ret = dp[ind][pre];
  if (ret != -1) return ret;
  long long a = 0, b = 0;
  a = v[ind].first * (v[ind].second - pre) + call(ind + 1, pre + 1);
  b = v[ind].first * (ses - v[ind].second) + call(ind + 1, pre);
  return ret = max(a, b);
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(make_pair(x, i));
  }
  sort(v.rbegin(), v.rend());
  cout << call(0, 0) << '\n';
}
