#include <bits/stdc++.h>
using namespace std;
int main() {
  long long Ans = 0;
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < (int)(N); i++) {
    cin >> A.at(i);
  }
  vector<long long> B(N);
  for (int i = 0; i < (int)(N); i++) {
    B.at(i) = i;
  }
  swap(B.at(0), B.at(1));
  long long wk_U;
  do {
    wk_U = 0;
    for (int i = 0; i < (int)(N); i++) {
      wk_U += A.at(i) * abs(i - B.at(i));
    }
    Ans = max(Ans, wk_U);
  } while (next_permutation(B.begin(), B.end()));
  cout << Ans << endl;
}
