#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < ((int)(N)); i++) {
    cin >> A.at(i);
  }
  vector<int> D(N);
  for (int i = 0; i < ((int)(N)); i++) D.at(i) = i;
  ll ma = 0;
  do {
    ll sum = 0;
    for (int i = 0; i < ((int)(N)); i++) {
      int d = abs(D[i] - i);
      if (d == 0) goto NEXT;
      sum += d * A[i];
    }
    if (ma < sum) {
      ma = sum;
    }
  NEXT:;
  } while (next_permutation(begin(D), end(D)));
  cout << ma << endl;
}
