#include <bits/stdc++.h>
using namespace std;
const long long max_n = 2e3 + 5;
vector<pair<long long, long long> > kids(max_n);
long long dp[max_n][max_n], n;
long long slove(long long l, long long r) {
  if (l >= r) return 0;
  if (dp[l][r]) return dp[l][r];
  long long i = n - (r - l + 1);
  return dp[l][r] = max(slove(l, r - 1) + kids[i].first * (r - kids[i].second),
                        slove(l + 1, r) + kids[i].first * (kids[i].second - l));
}
int main() {
  scanf("%d", &n);
  for (int i = 0, x; i < n; i++) {
    scanf("%d", &x);
    kids.push_back({x, i});
  }
  sort(kids.rbegin(), kids.rend());
  slove(0, n - 1);
  printf("%lld\n", dp[0][n - 1]);
  return 0;
}
