#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2020;
int n;
int a[N], p[N];
ll dp(int l, int r) {
  int dep = l + r + 1;
  if (dep > n) {
    return 0;
  }
  if (dep == n) {
    return 1LL * a[p[n]] * abs(l + 1 - p[n]);
  }
  ll res = max(1LL * a[p[dep]] * abs(l + 1 - p[dep]) + dp(l + 1, r),
               1LL * a[p[dep]] * abs(n - r - p[dep]) + dp(l, r + 1));
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    p[i] = i;
  }
  sort(p + 1, p + n + 1,
       [&](const int &i, const int &j) { return a[i] > a[j]; });
  printf("%lld\n", dp(0, 0));
  return 0;
}
