#include <bits/stdc++.h>
using namespace std;
int n, a[2010], b[2010];
int main() {
  cin >> n;
  int i;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i] = i;
  }
  int max = 0;
  while (next_permutation(b + 1, b + n + 1)) {
    int all = 0;
    for (i = 1; i <= n; ++i) {
      all = all + a[i] * abs(i - b[i]);
    }
    if (all > max) {
      max = all;
    }
  }
  cout << max;
  return 0;
}
