#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int n;
long long dp[2020][2020];
struct A {
  long long num, avl;
} a[5005];
int cmp(A a, A b) { return a.avl > b.avl; }
int work(int l, int r, int now) {
  if (l > r) return a[now].avl;
  if (dp[l][r] != -1) return dp[l][r];
  long long fist = work(l, r - 1, now + 1) + a[now].avl * abs(a[now].num - r);
  long long second = work(l + 1, r, now + 1) + a[now].avl * abs(a[now].num - l);
  dp[l][r] = max(dp[l][r], max(fist, second));
  return dp[l][r];
}
int main() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    cin >> a[i].avl;
    a[i].num = i;
  }
  sort(a + 1, a + n + 1, cmp);
  cout << work(1, n, 1);
  return 0;
}
