#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
using PII = pair<int64, int64>;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int& a : A) cin >> a;
  int64 ret = 0;
  for (int64 i = 0, j = n - 1; i <= j;) {
    bool left = true;
    int64 val = 0;
    int64 kk = -1;
    for (int64 k = 0; k < n; ++k) {
      int64 ii = abs(i - k) * A[k];
      int64 jj = abs(j - k) * A[k];
      if (val < ii) {
        val = ii;
        left = true;
        kk = k;
      }
      if (val < jj) {
        val = jj;
        left = false;
        kk = k;
      }
    }
    ret += val;
    A[kk] = 0;
    if (left) {
      ++i;
    } else {
      --j;
    }
  }
  cout << ret << "\n";
  return 0;
}
