#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
string s;
int k;
ll INF = 10000000000000000;
int main() {
  ll N;
  cin >> N;
  vi aka(N);
  ll A;
  for (int i = 0; i < N; i++) {
    cin >> A;
    aka[i] = A;
  }
  vi num(N);
  for (int i = 0; i < N; i++) {
    num[i] = i;
  }
  int ans, temp;
  ans = 0;
  while (next_permutation(num.begin(), num.end())) {
    temp = 0;
    for (int i = 0; i < N; i++) {
      temp += abs(num[i] - i) * aka[num[i]];
    }
    if (temp > ans) ans = temp;
  }
  cout << ans << endl;
}
