#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod = 1000000007;
ll n_pow(ll a, ll n) {
  if (n == 0) return 1;
  ll t = n_pow(a, n / 2);
  t *= t;
  t %= mod;
  if (n % 2 == 1) t *= a;
  return t % mod;
}
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = i;
  }
  ll ans = 0;
  do {
    ll tmp = 0;
    for (int i = 0; i < n; i++) {
      tmp += a[b[i]] * abs(i - b[i]);
    }
    if (tmp > ans) ans = tmp;
  } while (next_permutation(b.begin(), b.end()));
  cout << ans << endl;
  return 0;
}
