#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ll n;
  cin >> n;
  vector<ll> v(n), num(n, 0);
  for (int i = 0; i < n; i++) cin >> v.at(i);
  for (int i = 0; i < n; i++) {
    num.at(i) = i + 1;
  }
  ll sum = 0, ans = 0, i = 0;
  do {
    for (int x : num) {
      sum += v.at(i) * abs(x - 1 - i);
      i++;
    }
    ans = max(ans, sum);
    i = 0;
    sum = 0;
  } while (next_permutation(num.begin(), num.end()));
  cout << ans << endl;
}
