#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
using V = vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int ddx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int ddy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
long long int cmp1(pair<long long int, long long int> a,
                   pair<long long int, long long int> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int n;
  cin >> n;
  V<long long int> a(n);
  V<pair<long long int, long long int> > P(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    P[i].first = a[i];
    P[i].second = i;
  }
  sort((P).begin(), (P).end());
  reverse((P).begin(), (P).end());
  long long int dp[2020][2020];
  for (long long int i = 0; i <= n; i++) {
    for (long long int j = 0; j <= n; j++) {
      dp[i][j] = -300000000000000000;
    }
  }
  dp[0][0] = 0;
  for (long long int i = 0; i < n; i++) {
    long long int v = P[i].first;
    long long int ipos = P[i].second;
    for (long long int x = 0; x <= i; x++) {
      long long int y = i - x;
      dp[x + 1][y] = (dp[x + 1][y] > dp[x][y] + abs(ipos - x) * v
                          ? dp[x + 1][y]
                          : dp[x][y] + abs(ipos - x) * v);
      dp[x][y + 1] = (dp[x][y + 1] > dp[x][y] + abs(ipos - (n - 1 - y)) * v
                          ? dp[x][y + 1]
                          : dp[x][y] + abs(ipos - (n - 1 - y)) * v);
    }
  }
  long long int ans = -300000000000000000;
  for (long long int x = 0; x <= n; x++) {
    ans = (ans > dp[x][n - x] ? ans : dp[x][n - x]);
  }
  cout << ans << endl;
  return 0;
}
