#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 lh = -1, li = -1;
    for (int i = 0; i < N; i++) {
      if (children[i] * abs(i - left_bound) > lh && avail[i]) {
        lh = children[i] * abs(i - left_bound);
        li = i;
      }
    }
    long long rh = -1, ri = -1;
    for (int i = 0; i < N; i++) {
      if (children[i] * abs(i - right_bound) > rh && avail[i]) {
        rh = children[i] * abs(i - right_bound);
        ri = i;
      }
    }
    if (lh > rh) {
      ans += lh;
      avail[li] = false;
      left_bound++;
    } else {
      ans += rh;
      avail[ri] = 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;
}
