#include <bits/stdc++.h>
using namespace std;
const int N = 2020;
long long dp[N][N];
pair<int, int> a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[i] = pair<int, int>(-x, i);
  }
  sort(a + 1, a + n + 1);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == 0)
        dp[i][j] = 0;
      else
        dp[i][j] = -1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < i; j++) {
      int x = i - 1 - j, y = j;
      dp[x + 1][y] = max(dp[x + 1][y],
                         dp[x][y] - (a[i].first) * abs(a[i].second - (x + 1)));
      dp[x][y + 1] = max(dp[x][y + 1],
                         dp[x][y] - (a[i].first) * abs(a[i].second - (n - y)));
    }
  }
  long long ans = -1;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, dp[n - i][i]);
  }
  printf("%lld\n", ans);
}
