#include <bits/stdc++.h>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
int main() {
  i32 n;
  cin >> n;
  vector<i64> a(n);
  for (auto& e : a) cin >> e;
  i32 l = 0, r = n - 1, k = 0;
  i64 ans = 0;
  for (i32 i = 0; i < n; i++) {
    i32 maxi = 0;
    i64 score = 0;
    for (i32 j = 0; j < n; j++) {
      i64 tmp = max(a[j] * abs(r - j), a[j] * abs(l - j));
      if (tmp >= score) {
        score = tmp;
        maxi = j;
      }
    }
    if (abs(r - maxi) > abs(l - maxi)) {
      ans += a[maxi] * abs(r - maxi);
      r--;
      if (k) l++, k = 0;
    } else if (abs(r - maxi) < abs(l - maxi)) {
      ans += a[maxi] * abs(l - maxi);
      l++;
      if (k) r--, k = 0;
    } else {
      ans += a[maxi] * abs(l - maxi);
      k = 1;
    }
    a[maxi] = -1;
  }
  cout << ans << endl;
}
