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