#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e3;
const int INF = (int)1e9 + 7;
pair<int, int> p[N + 7];
long long dp[N + 7][N + 7];
int n;
long long f(int i, int l, int r) {
  if (i == 0) return 0;
  if (dp[l][r] != -1) return dp[l][r];
  long long x = f(i - 1, l + 1, r) + p[i].first * abs(l - p[i].second);
  long long y = f(i - 1, l, r - 1) + p[i].first * abs(r - p[i].second);
  return dp[l][r] = max(x, y);
}
int main(int argc, char *argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &p[i].first);
    p[i].second = i;
  }
  sort(p + 1, p + n + 1);
  memset(dp, -1, sizeof(dp));
  printf("%lld", f(n, 1, n));
  return 0;
}
