#include <bits/stdc++.h>
using namespace std;
unsigned long long N;
vector<unsigned long long> A;
vector<int> order;
int main() {
  cin >> N;
  int i, j, k;
  unsigned long long act;
  for (i = 0; i < N; i++) {
    cin >> act;
    A.push_back(act);
    order.push_back(i);
  }
  unsigned long long max_score = 0;
  unsigned long long score;
  while (next_permutation(order.begin(), order.end())) {
    score = 0;
    for (j = 0; j < N; j++) {
      i = order[j];
      score += (A[i] * abs(i - j));
    }
    if (score > max_score) {
      max_score = score;
    }
  }
  cout << max_score << endl;
}
