#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 k1 = 0, k2 = 0;
    int64_t sub1 = 0;
    for (int i = 0; i < n; ++i) {
      if (!s.count(i) && sub1 < a[i] * abs(i - l)) {
        sub1 = a[i] * abs(i - l);
        k1 = i;
      }
    }
    int64_t sub2 = 0;
    for (int i = 0; i < n; ++i) {
      if (!s.count(i) && sub2 < a[i] * abs(i - r)) {
        sub2 = a[i] * abs(i - r);
        k2 = i;
      }
    }
    if (sub1 >= sub2) {
      ans += sub1;
      s.insert(k1);
      ++l;
    } else {
      ans += sub2;
      s.insert(k2);
      --r;
    }
    ++cnt;
  }
  cout << ans << endl;
}
