#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  long long ans = 0;
  vector<int> perm(N);
  iota(perm.begin(), perm.end(), 0);
  bool finish = false;
  while (!finish) {
    long long asub = 0;
    for (int i = 0; i < N; i++) {
      asub += A[i] * abs(i - perm[i]);
    }
    ans = max(asub, ans);
    finish = !next_permutation(perm.begin(), perm.end());
  }
  cout << ans << endl;
  return 0;
}
