#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = int64_t;
const int N = 1e4 + 5;
ll _, x;
int n;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> _;
  pair<long long, long long> a[_];
  for (int i = 0; i < _; ++i) {
    cin >> x;
    a[i] = make_pair(x, i);
  }
  vector<int> kq;
  while (next_permutation(a, a + _)) {
    int ans = 0, j = 0;
    for (int i = 0; i < _; ++i) {
      if (a[i].second == i) {
        j = 1;
        break;
      }
      ans += (a[i].first * abs(a[i].second - i));
    }
    if (j) continue;
    kq.push_back(ans);
  }
  cout << *max_element(kq.begin(), kq.end());
  return 0;
}
