#include <bits/stdc++.h>
using namespace std;
int a[200010], f[10001];
int main() {
  int n, k;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int l = 1, r = n;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    const long long L = 0, R = 1;
    long long mxt = L, mx = -1, mxi = -1;
    for (int j = 1; j <= n; j++) {
      if (f[j]) continue;
      if (1ll * (a[j]) * abs(j - l) > mx) {
        mxt = L;
        mxi = j;
        mx = 1ll * (a[j]) * abs(j - l);
      }
      if (1ll * (a[j]) * abs(j - r) > mx) {
        mxt = R;
        mxi = j;
        mx = 1ll * (a[j]) * abs(j - r);
      }
    }
    if (mxt == L)
      l++;
    else
      r--;
    f[mxi] = 1;
    ans += mx;
  }
  printf("%lld\n", ans);
}
