#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
const int M = 1e6 + 10;
const int N = 2e3 + 10;
inline long long read() {
  long long b = 1, sum = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') b = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return b * sum;
}
struct node {
  int loc;
  long long val;
} a[N];
int n, m, k, T;
long long ans;
bool cmp(node x, node y) { return x.val > y.val; }
void dfs(long long res, int k, int l, int r) {
  if (k == n + 1) {
    ans = max(ans, res);
    return;
  }
  long long x = res;
  for (int i = k; i <= n; i++) {
    x += a[i].val * max(a[i].loc - l, r - a[i].loc);
  }
  if (x <= ans) return;
  dfs(res + a[k].val * (a[k].loc - l), k + 1, l + 1, r);
  dfs(res + a[k].val * (r - a[k].loc), k + 1, l, r - 1);
}
int main() {
  int i, j;
  n = read();
  for (i = 1; i <= n; i++) {
    a[i].val = read();
    a[i].loc = i;
  }
  sort(a + 1, a + n + 1, cmp);
  int l = 1, r = n;
  dfs(0, 1, 1, n);
  printf("%lld", ans);
  return 0;
}
