#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  vector<pair<int, int>> P(N);
  for (int i = 0; i < N; i++) {
    P[i] = make_pair(i, A[i]);
  }
  long long ans = 0;
  vector<long long> V(N);
  bool Map[N];
  memset(Map, false, sizeof(Map));
  int l = 0, r = N - 1;
  while (l <= r) {
    int li = -1;
    int ri = -1;
    int lm = -1;
    int rm = -1;
    for (int i = 0; i < N; i++) {
      if (!Map[i]) {
        long long temp = abs(l - i) * A[i];
        if (lm < temp) {
          lm = temp;
          li = i;
        }
      }
    }
    Map[li] = true;
    ans += lm;
    l++;
    if (l > r) break;
    for (int i = 0; i < N; i++) {
      if (!Map[i]) {
        long long temp = abs(r - i) * A[i];
        if (rm < temp) {
          rm = temp;
          ri = i;
        }
      }
    }
    Map[ri] = true;
    ans += rm;
    r--;
  }
  cout << ans << endl;
}
