#include <bits/stdc++.h>
using namespace std;
void sort2array(double *a, long *b, long n) {
  for (int i = 0; i < n; i++) {
    b[i] = i;
  }
  sort(b, b + n, [a](long i, long j) -> bool { return a[i] < a[j]; });
}
int wtover(int a, int b) {
  if (a % b > 0)
    return (a / b) + 1;
  else
    return a / b;
}
const int INF = 100000001, ID_MAX = 20;
int bi_e[ID_MAX] = {0};
int bi_max(long n) {
  int m = 0;
  for (m; pow(2, m) <= n; m++)
    ;
  m = m - 1;
  return m;
}
void bi_exs(long n) {
  for (int i = 0; i < (int)(ID_MAX); i++) {
    bi_e[i] = 0;
  }
  if (n < pow(2, ID_MAX)) {
    int m = bi_max(n);
    long l;
    for (m; m > -1; m--) {
      l = pow(2, m);
      bi_e[m] = n / l;
      n = n % l;
    }
  }
}
const int N = 2000;
int n, a[N] = {0}, b[N] = {0};
long dfs(int i, int lm, int rm) {
  if (lm == rm)
    return a[b[i]] * abs(b[i] - lm);
  else {
    if (abs(b[i] - lm) > abs(b[i] - rm))
      return a[b[i]] * abs(b[i] - lm) + dfs(i + 1, lm + 1, rm);
    else if (abs(b[i] - lm) < abs(b[i] - rm))
      return a[b[i]] * abs(b[i] - rm) + dfs(i + 1, lm, rm - 1);
    else {
      return max(a[b[i]] * abs(b[i] - lm) + dfs(i + 1, lm + 1, rm),
                 a[b[i]] * abs(b[i] - rm) + dfs(i + 1, lm, rm - 1));
    }
  }
}
int main() {
  int i;
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    b[i] = i;
  }
  long ans = 0;
  sort(b, b + n, [](int i, int j) -> bool { return a[i] > a[j]; });
  int lm = 0, rm = n - 1;
  ans = dfs(0, lm, rm);
  cout << ans << endl;
}
