#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N, 0);
  for (long long ii = 0; ii < N; ++ii) {
    cin >> A[ii];
  }
  vector<long long> idxSeq;
  for (long long ii = 0; ii < N; ++ii) {
    idxSeq.push_back(ii);
  }
  long long ans = 0;
  long long left = 0;
  long long right = N - 1;
  vector<long long> used(N, 0);
  for (long long step = 0; step < N; ++step) {
    long long maxVal = -1;
    long long maxIdx = -1;
    long long chooseLeft = -1;
    for (long long ii = 0; ii < N; ++ii) {
      if (used[ii]) continue;
      long long idx = idxSeq[ii];
      long long val1 = A[idx] * abs(idx - left);
      long long val2 = A[idx] * abs(idx - right);
      long long val = 0;
      long long tmp = 0;
      if (val1 > val2) {
        val = val1;
        tmp = 1;
      } else {
        val = val2;
      }
      if (val > maxVal) {
        maxVal = val;
        maxIdx = idx;
        chooseLeft = tmp;
      }
    }
    ans += maxVal;
    used[maxIdx] = 1;
    if (chooseLeft) {
      left++;
    } else {
      right--;
    }
  }
  cout << ans << endl;
  return 0;
}
