#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  vector<pair<int64_t, int64_t>> P(N);
  for (int64_t i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int64_t> ok(N, 0);
  int64_t s0 = 0, s1 = 0, max = 0;
  int64_t Ans = 0;
  for (int64_t i = 0; i < N / 2; i++) {
    s0 = 0;
    s1 = 0;
    max = 0;
    for (int64_t j = 0; j < N; j++) {
      for (int64_t k = 0; k < N; k++) {
        if (ok.at(j) == 0 && ok.at(k) == 0 && j != k &&
            (A.at(j) * abs(j - i) + A.at(k) * abs(k - (N - 1 - i))) > max) {
          max = A.at(j) * abs(j - i) + A.at(k) * abs(k - (N - 1 - i));
          s0 = j;
          s1 = k;
        }
      }
    }
    Ans += max;
    ok.at(s0) = 1;
    ok.at(s1) = 1;
  }
  if (N % 2 == 1) {
    for (int64_t j = 0; j < N; j++) {
      if (ok.at(j) == 0) {
        Ans += A.at(j) * abs(j - N / 2);
        break;
      }
    }
  }
  cout << Ans << endl;
}
