#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  long long n;
  cin >> n;
  long long a[n + 1], i, j, l, r;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  l = 1;
  r = n;
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    long long ma = 0, index = -1, move = 0;
    for (j = 1; j <= n; j++) {
      if (a[j] == -1) continue;
      ma = max(ma, a[j] * abs(r - j));
      ma = max(ma, a[j] * abs(j - l));
      if (ma == a[j] * abs(r - j)) {
        index = j;
        move = r;
      } else if (ma == a[j] * abs(j - l)) {
        index = j;
        move = l;
      }
    }
    if (move == l) {
      l++;
    } else {
      r--;
    }
    ans += ma;
    a[index] = -1;
  }
  cout << ans << "\n";
  return 0;
}
