#include <bits/stdc++.h>
using namespace std;
long long N, K, i, j, k, MOD, n, m, A[2001], ans, n1, n2, t;
int main() {
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  ans = 0;
  for (i = 0; i < N / 2; i++) {
    t = 0;
    for (j = 0; j < N; j++) {
      for (k = j + 1; k < N; k++) {
        if (k == j) continue;
        m = abs(j - i) * A[j] + abs(N - 1 - i - k) * A[k];
        if (t < m) {
          n1 = j;
          n2 = k;
          t = m;
        }
        m = abs(j - k) * A[k] + abs(N - 1 - i - j) * A[j];
        if (t < m) {
          n1 = k;
          n2 = j;
          t = m;
        }
      }
    }
    ans += t;
    A[n1] = 0;
    A[n2] = 0;
  }
  if (N % 2 == 1) {
    for (i = 0; i < N; i++) {
      ans += A[i] * abs((N - 1) / 2 - i);
    }
  }
  cout << ans;
}
