#include <bits/stdc++.h>
using namespace std;

const int N = 2005;

pair<int, int> a[N];

int n;
long long dp[N][N];
long long f(int x, int l) {
  if (x == n) return 0LL;
  if (~dp[x][l]) return dp[x][l];

  int r = n - (x-l) - 1;
  return dp[x][l] = max(
    1LL * a[x].first * abs(a[x].second - l) + f(x+1, l+1),
    1LL * a[x].first * abs(a[x].second - r) + f(x+1, l)
  );
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }

  sort(a, a + n, greater<pair<int, int>>());
  memset(dp, -1, sizeof dp);

  printf("%lld\n", f(0, 0));
  return 0;
}
