#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  ll ar[n];
  set<ll> s1, s2;
  for (ll i = 0; i < n; i++) {
    cin >> ar[i];
    s1.insert(i);
    s2.insert(i);
  }
  ll ans = 0;
  while (s1.size()) {
    ll st, en, ma = -1;
    for (ll x : s1) {
      ll mi = *s2.begin(), mm = *s2.rbegin();
      if (abs(x - mi) > abs(x - mm)) {
        if (ar[x] * (abs(x - mi)) > ma) {
          st = x, en = mi;
          ma = ar[x] * abs(x - mi);
        }
      } else {
        if (ar[x] * (abs(x - mm)) > ma) {
          st = x, en = mm;
          ma = ar[x] * abs(x - mm);
        }
      }
    }
    s1.erase(st);
    s2.erase(en);
    ans += ma;
  }
  cout << ans << "\n";
}
