#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[200005], f[200005];
int flag[200005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int L = 1, R = n;
  long long res = 0;
  for (int sl = 1; sl <= n; ++sl) {
    int ma = 0, id = 0;
    for (int i = 1; i <= n; ++i)
      if (!flag[i])
        if (ma <= a[i] * max(abs(i - L), abs(R - i))) {
          ma = a[i] * max(abs(i - L), abs(R - i));
          id = i;
        }
    flag[id] = 1;
    if (abs(id - L) > abs(id - R)) {
      res = res + a[id] * abs(id - L);
      L++;
    } else {
      res = res + a[id] * abs(id - R);
      R--;
    }
  }
  cout << res;
}
