#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1e18;
const double pi = 3.14159265358979323846;
int main() {
  long long n;
  cin >> n;
  pair<long long, long long> v[n + 1];
  for (long long i = 1; i < n + 1; i++) {
    cin >> v[i].second;
    v[i].first = i;
  }
  long long ans = 0;
  do {
    long long sum = 0;
    for (int i = 1; i < n + 1; i++) {
      sum += v[i].second * abs(i - v[i].first);
    }
    ans = max(ans, sum);
  } while (next_permutation(v + 1, v + n + 1));
  cout << ans << endl;
}
