#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 998244353;
const long long MX = 1000001;
int N;
long long ans = 0;
void solve() {
  cin >> N;
  int left_bound = 0, right_bound = N - 1;
  vector<long long> children(N);
  for (int i = 0; i < N; i++) cin >> children[i];
  vector<bool> avail(N, true);
  while (left_bound <= right_bound) {
    long long bh = -1, bi = -1;
    for (int i = 0; i < N; i++) {
      if (children[i] * abs(i - left_bound) > bh && avail[i]) {
        bh = children[i] * abs(i - left_bound);
        bi = i;
      }
    }
    ans += bh;
    avail[bi] = false;
    left_bound++;
    bh = -1;
    bi = -1;
    for (int i = 0; i < N; i++) {
      if (children[i] * abs(i - right_bound) > bh && avail[i]) {
        bh = children[i] * abs(i - right_bound);
        bi = i;
      }
    }
    if (bi != -1) {
      ans += bh;
      avail[bi] = false;
    }
    right_bound--;
  }
  cout << ans;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  long long T;
  T = 1;
  while (T--) solve();
  return 0;
}
