#include <bits/stdc++.h>
using namespace std;
const int inf = pow(10, 9);
const int nil = -1;
int i, j, n, m;
long long ans, k;
long long a[2001];
int main() {
  scanf(" %d", &n);
  for (i = 0; i < n; i++) {
    scanf(" %lld", &k);
    a[i + 1] = k;
  }
  int left = 1;
  int right = n;
  ans = 0;
  for (i = 0; i < n; i++) {
    int maxjoy = 0;
    int target = 0;
    for (j = 1; j <= n; j++) {
      int joy = a[j] * max(abs(j - left), abs(j - right));
      if (joy > maxjoy) {
        target = j;
        maxjoy = joy;
      }
    }
    if (abs(target - left) > abs(target - right)) {
      ans += abs(target - left) * a[target];
      left++;
    } else {
      ans += abs(target - right) * a[target];
      right--;
    }
    a[target] = 0;
  }
  printf("%lld\n", ans);
}
