#include <bits/stdc++.h>
using namespace std;
long long v[2048];
long long ans, A, B;
int sel[2048];
int j, l, r, i, n, mx, pmx, dest;
int main() {
  cin >> n;
  for (i = 0; i < n; ++i) cin >> v[i];
  l = 0;
  r = n - 1;
  ans = 0;
  for (i = 0; i < n; ++i) {
    mx = 0;
    for (j = 0; j < n; ++j)
      if (!sel[j]) {
        A = v[j] * abs(j - l);
        B = v[j] * abs(r - j);
        if (A > B) {
          if (mx < A) {
            pmx = j;
            mx = A;
            dest = 1;
          }
        } else {
          if (mx < B) {
            pmx = j;
            mx = B;
            dest = 0;
          }
        }
      }
    ans += mx;
    sel[pmx] = 1;
    if (dest)
      ++l;
    else
      --r;
  }
  cout << ans;
  return 0;
}
