#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int64_t> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  set<int> s;
  int64_t ans = 0;
  int l = 0, r = n - 1;
  int cnt = 0;
  while (cnt < n) {
    int k = 0;
    if (cnt % 2 == 0) {
      int64_t sub = 0;
      for (int i = 0; i < n; ++i) {
        if (!s.count(i) && sub < a[i] * abs(i - l)) {
          sub = a[i] * abs(i - l);
          k = i;
        }
      }
      s.insert(k);
      ans += (int64_t)sub;
      ++l;
      ++cnt;
    } else {
      int64_t sub = 0;
      for (int i = 0; i < n; ++i) {
        if (!s.count(i) && sub < a[i] * abs(i - r)) {
          sub = a[i] * abs(i - r);
          k = i;
        }
      }
      s.insert(k);
      ans += (int64_t)sub;
      --r;
      ++cnt;
    }
  }
  cout << ans << endl;
}
