#include <bits/stdc++.h>
using namespace std;
vector<long long> A(2000);
vector<long long> temp(2000);
vector<bool> flag(2000);
long long tmp, tmpval;
long long ans = 0;
long long func(long long l, long long r, long long sum, long long N) {
  if (l > r) return sum;
  for (long long i = 0; i < N; i++) {
    temp[i] = 0;
  }
  for (long long i = 0; i < N; i++) {
    if (flag[i]) {
      temp[i] = A[i] * max(abs(i - l), abs(i - r));
    }
  }
  tmp = 0;
  tmpval = 0;
  for (long long i = 0; i < N; i++) {
    if (tmpval < temp[i]) {
      tmp = i;
      tmpval = temp[i];
    }
  }
  flag[tmp] = false;
  if (abs(tmp - l) < abs(tmp - r)) {
    return func(l, r - 1, sum + tmpval, N);
  } else {
    return func(l + 1, r, sum + tmpval, N);
  }
}
int main(void) {
  long long N;
  cin >> N;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    flag[i] = true;
  }
  cout << func(0, N - 1, 0, N) << endl;
  return 0;
}
