#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<bool> is(n);
  long long l = 0, r = n - 1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long mx = -1;
    for (int j = 0; j < n; j++) {
      if (mx == -1 && is[j] == false) mx = j;
      if (mx == -1 || is[j]) continue;
      if (a[mx] * max(abs(mx - l), abs(mx - r)) <
          a[j] * max(abs(j - l), abs(j - r))) {
        mx = j;
      }
    }
    is[mx] = true;
    if (abs(mx - l) > abs(mx - r)) {
      ans += a[mx] * abs(mx - l);
      l++;
    } else {
      ans += a[mx] * abs(mx - r);
      r--;
    }
  }
  cout << ans << endl;
  return 0;
}
