#include <bits/stdc++.h>
using namespace std;
int dp[2010][2010];
int A[2010];
pair<int, int> p[2010];
int N;
int calc(int x = 0, int L = 0, int R = N - 1) {
  if (x == N) return 0;
  if (dp[L][R] != -2000000000) return dp[L][R];
  dp[L][R] =
      max(dp[L][R], calc(x + 1, L + 1, R) + p[x].first * abs(p[x].second - L));
  dp[L][R] =
      max(dp[L][R], calc(x + 1, L, R - 1) + p[x].first * abs(p[x].second - R));
  return dp[L][R];
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) p[i] = {A[i], i};
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dp[i][j] = -2000000000;
  sort(p, p + N, greater<pair<int, int>>());
  cout << calc() << endl;
  return 0;
}
