#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  long long A[2010];
  long long B[2010];
  long long i;
  long long j;
  long long p;
  long long q;
  long long q11;
  long long q12;
  long long q21;
  long long q22;
  cin >> N;
  p = 0;
  for (i = 1; i <= N; i++) {
    cin >> A[i];
    B[i] = i;
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      q11 = max(B[i] - i, i - B[i]);
      q12 = max(B[i] - j, j - B[i]);
      q21 = max(B[j] - i, i - B[j]);
      q22 = max(B[j] - j, j - B[j]);
      if (A[B[i]] * q11 + A[B[j]] * q22 < A[B[j]] * q21 + A[B[i]] * q12) {
        p = p - (A[B[i]] * q11 + A[B[j]] * q22);
        p = p + (A[B[j]] * q21 + A[B[i]] * q12);
        q = B[i];
        B[i] = B[j];
        B[j] = q;
      }
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      q11 = max(B[i] - i, i - B[i]);
      q12 = max(B[i] - j, j - B[i]);
      q21 = max(B[j] - i, i - B[j]);
      q22 = max(B[j] - j, j - B[j]);
      if (A[B[i]] * q11 + A[B[j]] * q22 < A[B[j]] * q21 + A[B[i]] * q12) {
        p = p - (A[B[i]] * q11 + A[B[j]] * q22);
        p = p + (A[B[j]] * q21 + A[B[i]] * q12);
        q = B[i];
        B[i] = B[j];
        B[j] = q;
      }
    }
  }
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= N; j++) {
      q11 = max(B[i] - i, i - B[i]);
      q12 = max(B[i] - j, j - B[i]);
      q21 = max(B[j] - i, i - B[j]);
      q22 = max(B[j] - j, j - B[j]);
      if (A[B[i]] * q11 + A[B[j]] * q22 < A[B[j]] * q21 + A[B[i]] * q12) {
        p = p - (A[B[i]] * q11 + A[B[j]] * q22);
        p = p + (A[B[j]] * q21 + A[B[i]] * q12);
        q = B[i];
        B[i] = B[j];
        B[j] = q;
      }
    }
  }
  for (i = 1; i <= N; i++) {
    cout << "B[" << i << "]=" << B[i] << endl;
  }
  cout << p << endl;
  return 0;
}
