#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 5;
const int M = 1e9 + 7;
int n;
long long dp[MAXN][MAXN];
vector<pair<long long, int>> v(MAXN);
long long solve(int i, int j) {
  int ind = (n - 1) - (j - i);
  if (dp[i][j] != -1) return dp[i][j];
  dp[i][j] = max(
      i == (n - 1) ? 0
                   : abs(v[ind].second - i) * v[ind].first + solve(i + 1, j),
      j == 0 ? 0 : abs(v[ind].second - j) * v[ind].first + solve(i, j - 1));
  return dp[i][j];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> v[i].first;
    v[i].second = i;
  }
  sort(v.rbegin(), v.rend());
  long long ans = solve(0, n - 1);
  printf("%lld", ans);
  return 0;
}
