#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
pair<int, int> a[maxn];
long long dp[maxn][maxn];
long long solve(int cnt, int l, int r) {
  if (l > r) return 0;
  if (~dp[l][r]) return dp[l][r];
  long long ans =
      a[cnt].first * abs(a[cnt].second - l) + solve(cnt + 1, l + 1, r);
  ans = max(ans,
            a[cnt].first * abs(a[cnt].second - r) + solve(cnt + 1, l, r - 1));
  return dp[l][r] = ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int num;
    cin >> num;
    a[i] = {num, i};
  }
  sort(a + 1, a + n + 1, greater<pair<int, int> >());
  memset(dp, -1, sizeof(dp));
  cout << solve(1, 1, n) << endl;
  return 0;
}
