#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000;
int N;
pair<int, int> A[MAXN + 10];
long long dp[MAXN + 10][MAXN + 10];
long long solve(int l, int r) {
  long long &ret = dp[l][r];
  if (ret != -1) return ret;
  ret = 0;
  int t = l + N + 1 - r + 1;
  if (t == N + 1) return ret = 0;
  ret = max(ret, solve(l + 1, r) +
                     (long long)abs(A[t].second - (l + 1)) * A[t].first);
  ret = max(ret, solve(l, r - 1) +
                     (long long)abs(A[t].second - (r - 1)) * A[t].first);
  return ret;
}
int main() {
  int i, j;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%d", &A[i].first), A[i].second = i;
  sort(A + 1, A + N + 1, greater<pair<int, int> >());
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", solve(0, N + 1));
}
