#include <bits/stdc++.h>
using namespace std;
const static long long MOD = 1e9 + 7;
int main() {
  long long n;
  cin >> n;
  vector<long long> a;
  vector<long long> model;
  for (long long i = 0; i < n; i++) {
    long long t;
    cin >> t;
    a.push_back(t);
    model.push_back(i);
  }
  long long ans = 0;
  do {
    long long tmp = 0;
    for (long long i = 0; i < n; i++) {
      tmp += abs(model[i] - i) * a[model[i]];
    }
    ans = max(tmp, ans);
  } while (next_permutation((model).begin(), (model).end()));
  cout << ans << endl;
}
