#include <bits/stdc++.h>
using namespace std;
int n;
pair<long long, long long> A[3000];
long long dp[3000][300];
long long mabs(long long a) { return a < 0 ? -a : a; }
long long solve(int idx, int left) {
  if (idx == n) return 0;
  long long& ref = dp[idx][left];
  if (ref != -1) return ref;
  int right = idx - left;
  ref = mabs(A[idx].second - left) * A[idx].first + solve(idx + 1, left + 1);
  ref = max(ref, mabs(A[idx].second - (n - right - 1)) * A[idx].first +
                     solve(idx + 1, left));
  return ref;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i].first;
    A[i].second = i;
  }
  memset(dp, -1, sizeof dp);
  sort(A, A + n);
  reverse(A, A + n);
  cout << solve(0, 0) << endl;
  return 0;
}
