#include <bits/stdc++.h>
using namespace std;
long long n;
long long dp[2005][2005];
long long second;
long long first;
struct node {
  int rt;
  int num;
} a[5005];
bool cmp(node a, node b) { return a.num > b.num; }
int work(int now, int l, int r) {
  if (l > r) return a[now].num;
  if (dp[l][r] != -1) return dp[l][r];
  first = work(now + 1, l + 1, r) + a[now].num * abs(a[now].rt - l);
  second = work(now + 1, l, r - 1) + a[now].num * abs(a[now].rt - r);
  dp[l][r] = max(dp[l][r], max(first, second));
  return dp[l][r];
}
int read() {
  int sum = 0;
  int flag = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    sum *= 10;
    sum += (ch - '0');
    ch = getchar();
  }
  return sum * flag;
}
int main() {
  n = read();
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    a[i].num = read();
    a[i].rt = i;
  }
  sort(a + 1, a + n + 1, cmp);
  cout << work(1, 1, n) << endl;
  return 0;
}
