#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> vec(3000);
long long dp[3000][3000];
long long n;
long long solve(long long l, long long r) {
  if (l > r) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  long long idx = (n - (r - l + 1) + 1);
  long long ans1 = abs(l - vec[idx].second) * vec[idx].first + solve(l + 1, r);
  long long ans2 = abs(r - vec[idx].second) * vec[idx].first + solve(l, r - 1);
  return dp[l][r] = max(ans1, ans2);
}
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> vec[i].first;
    vec[i].second = i;
  }
  sort(vec.begin() + 1, vec.begin() + 1 + n);
  reverse(vec.begin() + 1, vec.begin() + 1 + n);
  memset(dp, -1, sizeof(dp));
  long long ans = solve(1, n);
  cout << ans << endl;
}
