#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
pair<int, int> A[N];
long long dp[N][N];
long long solve(int idx, int l, int r) {
  if (l > r) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  long long res = max(
      1LL * A[idx].first * abs(A[idx].second - l) + solve(idx + 1, l + 1, r),
      1LL * A[idx].first * abs(A[idx].second - r) + solve(idx + 1, l, r - 1));
  dp[l][r] = res;
  return dp[l][r];
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, t;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> t;
    A[i] = {t, i};
  }
  sort(A + 1, A + n + 1, [&](pair<int, int> &p1, pair<int, int> &p2) {
    return p1.first > p2.first;
  });
  cout << solve(1, 1, n) << endl;
  return 0;
}
