#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
long long dp[N][N];
struct p {
  int x, id;
  bool operator<(const p& a) const { return x > a.x; }
} a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i].x), a[i].id = i;
  sort(a + 1, a + n + 1);
  for (int k = 1; k <= n; k++)
    for (int i = 0; i < k; i++) {
      int j = k - 1 - i;
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[k].x * (a[k].id - (i + 1)));
      dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a[k].x * (n - j - a[k].id));
    }
  long long ans = 0;
  for (int i = 0; i <= n; i++) ans = max(ans, dp[i][n - i]);
  printf("%lld\n", ans);
  return 0;
}
