#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> v;
  for (int i = (0); i < (int)(N); i++) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  vector<bool> used(N, false);
  int L = 0, R = N - 1;
  int cnt = N;
  long long ret = 0;
  while (cnt > 0) {
    long long lbest = -1, rbest = -1;
    int li = -1, ri = -1;
    for (int i = (0); i < (int)(N); i++) {
      if (used[i]) continue;
      long long lscore = v[i] * abs(i - L);
      if (lbest < lscore) {
        lbest = lscore;
        li = i;
      } else if (lbest == lscore) {
        if (abs(li - L) > abs(i - L)) {
          li = i;
        }
      }
      long long rscore = v[i] * abs(i - R);
      if (rbest < rscore) {
        rbest = rscore;
        ri = i;
      } else if (rbest == rscore) {
        if (abs(ri - R) > abs(i - R)) {
          ri = i;
        }
      }
    }
    if (rbest < lbest) {
      ret += lbest;
      used[li] = true;
      L++;
    } else if (rbest > lbest) {
      ret += rbest;
      used[ri] = true;
      R--;
    } else {
      if (abs(N - 1 - R) > L) {
        ret += lbest;
        used[li] = true;
        L++;
      } else {
        ret += rbest;
        used[ri] = true;
        R--;
      }
    }
    cnt--;
  }
  cout << ret << endl;
  return 0;
}
