#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > A(2002);
int n;
map<vector<int>, long long> dp;
long long solve(int l, int r, int pos) {
  if (l > r) return 0;
  if (pos >= n) return 0;
  long long ret =
      A[pos].first * abs(A[pos].second - l) + solve(l + 1, r, pos + 1);
  ret = max(ret,
            A[pos].first * abs(A[pos].second - r) + solve(l, r - 1, pos + 1));
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(A.rbegin(), A.rend());
  long long ans = solve(0, n - 1, 0);
  cout << ans << endl;
  return 0;
}
