#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long, long>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
int main(void) {
  ll N, M, A, B, C, D, E, F, G, K, L, W, H, P, Q, R, V, X, Y;
  cin >> N;
  vector<ll> xy;
  ll a[N];
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
    xy.push_back(i);
  }
  ll ans = 0;
  do {
    ll j = 0;
    ll total = 0;
    for (auto x : xy) {
      total += abs(j - x) * a[j];
      j++;
    }
    ans = max(ans, total);
  } while (std::next_permutation(xy.begin(), xy.end()));
  cout << ans << endl;
}
