#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  for (ll i = 0; i < n; i++) {
    cin >> mp[i];
  }
  ll l = 0, r = n - 1;
  ll sum = 0;
  while (n--) {
    ll idx = -1;
    ll nax = 0;
    for (auto i : mp) {
      if (max(abs(i.first - l), abs(i.first - r)) * i.second > nax) {
        nax = max(abs(i.first - l), abs(i.first - r)) * i.second;
        idx = i.first;
      }
    }
    sum += nax;
    if (abs(idx - l) > abs(idx - r)) {
      l++;
    } else {
      r--;
    }
    mp.erase(idx);
  }
  cout << sum << endl;
}
