#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 (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> ok(N, 0);
  int64_t s = 0, max = 0;
  int64_t Ans = 0;
  for (int i = 0; i < N / 2; i++) {
    s = 0;
    max = 0;
    for (int j = 0; j < N; j++) {
      if (ok.at(j) == 0 && A.at(j) * abs(j - i) > max) {
        max = A.at(j) * abs(j - i);
        s = j;
      }
    }
    Ans += max;
    ok.at(s) = 1;
    s = 0;
    max = 0;
    for (int j = 0; j < N; j++) {
      if (ok.at(j) == 0 && A.at(j) * abs(j - (N - 1 - i)) > max) {
        max = A.at(j) * abs(j - (N - 1 - i));
        s = j;
      }
    }
    Ans += max;
    ok.at(s) = 1;
  }
  if (N % 2 == 1) {
    for (int j = 0; j < N; j++) {
      if (ok.at(j) == 0) {
        Ans += A.at(j) * abs(j - N / 2);
        break;
      }
    }
  }
  cout << Ans << endl;
}
