#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 2e6 + 10;
const double eps = 1e-1;
long long n;
long long l, r;
long long max(long long x, long long y) { return x > y ? x : y; }
struct Node {
  long long x, id;
  bool operator<(const Node &p) const { return x > p.x; }
} a[maxn];
long long dp[210][2100];
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i].x);
    a[i].id = i;
  }
  sort(a + 1, a + n + 1);
  long long tmp = 0, ans = 0;
  Node b;
  for (int i = 1; i <= n; i++) {
    b = a[i];
    for (long long l = 1, r = n - i + 1; r <= n; l++, r++) {
      dp[i][l] = max(dp[i][l], dp[i - 1][l - 1] + abs(b.id - l) * b.x);
      dp[i][l - 1] = max(dp[i][l - 1], dp[i - 1][l - 1] + abs(b.id - r) * b.x);
    }
  }
  for (int i = 1; i <= n; i++) ans = max(ans, dp[n][i]);
  printf("%lld\n", ans);
  return 0;
}
