#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long point[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      point[i][j] = (long long)abs(i - j) * A[i];
    }
  }
  int l = 0, r = N - 1;
  bool exist[N];
  memset(exist, false, sizeof(exist));
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int lmax = 0, rmax = 0, lidx, ridx;
    for (int j = 0; j < N; j++) {
      if (!exist[j]) {
        if (lmax <= point[j][l]) {
          lidx = j;
          lmax = point[j][l];
        }
        if (rmax <= point[j][r]) {
          ridx = j;
          rmax = point[j][r];
        }
      }
    }
    if (lmax > rmax) {
      ans += lmax;
      l++;
      exist[lidx] = true;
    } else {
      ans += rmax;
      r--;
      exist[ridx] = true;
    }
  }
  cout << ans << endl;
  return 0;
}
