#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  long long A[2005];
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i * 2 < N; i++) {
    long long maxval = -1;
    long long maxidx = -1;
    long long pos = i;
    for (int j = 0; j < N; j++) {
      if (A[j] != -1) {
        long long val = A[j] * abs(j - pos);
        if (val > maxval) {
          maxval = val;
          maxidx = j;
        }
      }
    }
    ans += maxval;
    A[maxidx] = -1;
    if (i == N - 1 - i) continue;
    maxval = -1;
    maxidx = -1;
    pos = N - 1 - i;
    for (int j = 0; j < N; j++) {
      if (A[j] != -1) {
        long long val = A[j] * abs(j - pos);
        if (val > maxval) {
          maxval = val;
          maxidx = j;
        }
      }
    }
    A[maxidx] = -1;
    ans += maxval;
  }
  cout << ans << endl;
  return 0;
}
