#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int sum = 0, ans = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> y(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    y.at(i) = i;
  }
  while (next_permutation(y.begin(), y.end())) {
    sum = 0;
    for (int x = 0; x < n; x++) {
      sum += a.at(x) * abs(x - y.at(x));
    }
    if (sum > ans) ans = sum;
  }
  cout << ans << endl;
}
