#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  bool used[n];
  ll res = 0;
  ll upper = n;
  ll lower = 1;
  for (int i = 0; i < (n); ++i) {
    ll max_now = 0;
    ll max_idx = -1;
    for (int j = 0; j < (n); ++j) {
      if (!used[j]) {
        ll dist = max(upper - j - 1, j + 1 - lower);
        if (max_now < dist * a[j]) {
          max_now = dist * a[j];
          max_idx = j;
        }
      }
    }
    res += max_now;
    used[max_idx] = true;
    if (upper - max_idx - 1 > max_idx + 1 - lower) {
      upper -= 1;
    } else {
      lower += 1;
    }
  }
  cout << res << endl;
  return 0;
}
