#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  ll ans = 0;
  vector<bool> used(N);
  ll l = 0, r = N - 1;
  while (l <= r) {
    ll v = -1, temp = -1, side = 0;
    for (ll i = 0; i < N; i++) {
      if (!used[i]) {
        if (temp < A[i] * abs(l - i)) {
          temp = A[i] * abs(l - i);
          v = i;
          side = -1;
        }
        if (temp < A[i] * abs(r - i)) {
          temp = A[i] * abs(r - i);
          v = i;
          side = 1;
        }
      }
    }
    ans += temp;
    used[v] = true;
    if (side < 0)
      l++;
    else
      r--;
  }
  cout << ans << '\n';
  return 0;
}
