#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
int main(void) {
  int N;
  cin >> N;
  vector<int> F(N);
  vector<int> prm(N);
  for (int i = 0; i < N; i++) {
    cin >> F[i];
    prm[i] = i + 1;
  }
  ll ans = 0;
  do {
    ll sum = 0;
    for (int i = 0; i < N; i++) {
      int j;
      for (j = 0; j < N; j++) {
        if (prm[j] == i + 1) break;
      }
      sum += F[i] * abs((i + 1) - (j + 1));
    }
    ans = max(ans, sum);
  } while (next_permutation((prm).begin(), (prm).end()));
  cout << ans << endl;
}
