#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct child {
  ll idx;
  ll act;
};
bool compare(child a, child b) { return a.idx < b.idx; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<child> C(N);
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    C.at(i) = child{i, a};
  }
  ll ans = 0;
  do {
    ll res = 0;
    for (int i = 0; i < N; ++i) {
      res += C.at(i).act * abs(C.at(i).idx - i);
    }
    ans = max(ans, res);
  } while (next_permutation(C.begin(), C.end(), compare));
  cout << ans << endl;
  return 0;
}
