#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7, N = 2005;
long long a[N], b[N];
long long get(long long i) { return a[i] * abs(i - b[i]); }
long long ans = 0, n;
void go() {
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      long long cur = get(i) + get(j);
      swap(b[i], b[j]);
      long long new_cur = get(i) + get(j);
      if (new_cur <= cur) swap(b[i], b[j]);
    }
  }
  long long cans = 0;
  for (long long i = 0; i < n; i++) cans += get(i);
  ans = max(ans, cans);
}
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) b[i] = i;
  mt19937 rng(time(0));
  for (long long tt = 0; tt < 300; tt++) {
    shuffle(b, b + n, rng);
    go();
  }
  cout << ans << endl;
}
