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