#include <bits/stdc++.h>
using namespace std;
long long a[30000], vs[20002];
int main() {
  ios_base::sync_with_stdio(false);
  long long i, j, m, k, n, t, l = 0, mxx, mx1, r, c, x, y = 1e9 + 7, ans = 0,
                              ind, sum = 0, ind1;
  cin >> n;
  l = 1;
  r = n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (j = 1; j <= n; j++) {
    ans = 0;
    for (i = 1; i <= n; i++) {
      if (vs[i] == 0) {
        if (a[i] * abs(l - i) > ans) {
          ind = i;
          ind1 = l;
          ans = a[i] * (abs(l - i));
        }
        if (a[i] * abs(r - i) > ans) {
          ind = i;
          ind1 = r;
          ans = a[i] * (abs(r - i));
        }
      }
    }
    sum += ans;
    if (ind1 == l)
      l++;
    else
      r--;
    vs[ind] = 1;
  }
  cout << sum << endl;
  return 0;
}
