#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a;
long long dp[2005][2005];
int n;
long long solve(int l, int r) {
  if (l > r) return 0;
  if (dp[l][r]) return dp[l][r];
  int i = r - l;
  return dp[l][r] = max(solve(l, r - 1) + a[i].first * (r - a[i].second),
                        solve(l + 1, r) + a[i].first * (a[i].second - l));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    a.push_back({x, i});
  }
  sort(a.begin(), a.end());
  solve(0, n - 1);
  printf("%lld\n", dp[0][n - 1]);
  return 0;
}
