#include <bits/stdc++.h>
using namespace std;
using LL = long long;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long w[2020][2020];
long long a[2020];
int mk[2020];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      w[i][j] = 1ll * abs(i - j) * (a[i]);
    }
  }
  int pt1 = 1, pt2 = n;
  long long ans = 0;
  while (pt1 <= pt2) {
    long long ma = -1;
    int pt = 0, fg = 0;
    for (int i = 1; i <= n; i++) {
      if (mk[i]) continue;
      if (w[i][pt1] > ma) {
        ma = w[i][pt1];
        pt = i;
        fg = 1;
      }
      if (w[i][pt2] > ma) {
        ma = w[i][pt2];
        pt = i;
        fg = 2;
      }
    }
    ans += ma;
    mk[pt] = 1;
    if (fg == 1)
      pt1++;
    else
      pt2--;
  }
  printf("%lld\n", ans);
  return 0;
}
