#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 2001;
int a[maxn], p[maxn];
long long dp[maxn][maxn];
int cmp(int i, int j) { return a[i] > a[j]; }
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, cmp);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      int l = j + 1;
      int r = n - i + j;
      if (l - 1 >= 1)
        dp[l][r] =
            max(dp[l][r], dp[l - 1][r] + 11L * abs(a[p[i]] * (p[i] - l + 1)));
      if (r + 1 <= n)
        dp[l][r] =
            max(dp[l][r], dp[l][r + 1] + 11L * abs(a[p[i]] * (p[i] - r - 1)));
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i][i - 1]);
  printf("%d\n", ans);
  return 0;
}
