#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, dp[2009], i, j, f[2009], x[2009], pasdp, pasi, pasx,
    jj;
set<pair<long long, long long> > s[2009];
set<pair<long long, long long> >::iterator it, t;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a;
  for (i = 1; i <= a; i++) cin >> f[i];
  for (i = 1; i <= a; i++) {
    for (j = 1; j <= a; j++) {
      s[i].insert(make_pair(-f[j] * abs(i - j), j));
    }
  }
  it = s[1].begin();
  dp[1] = -(*it).first;
  x[1] = (*it).second;
  pasi = (*it).second;
  for (j = 1; j <= a; j++) {
    s[j].erase(s[j].lower_bound(make_pair(-f[pasi] * abs(j - pasi), pasi)));
  }
  for (i = 2; i <= a; i++) {
    pasdp = 0;
    pasi = 0;
    pasx = 0;
    jj = 0;
    if (pasdp < dp[i - 1] - (*(s[i].begin())).first) {
      pasdp = dp[i - 1] - (*(s[i].begin())).first;
      pasi = (*(s[i].begin())).second;
      pasx = 0;
      x[i] = (*(s[i].begin())).second;
    }
    for (j = 1; j < i; j++) {
      c = dp[i - 1] + f[x[j]] * abs(i - x[j]) - f[x[j]] * abs(j - x[j]);
      it = s[j].begin();
      if ((*it).second != x[j]) {
        c -= (*it).first;
        if (pasdp < c) {
          jj = j;
          pasdp = c;
          pasi = (*it).second;
        }
      } else {
        it++;
        c -= (*it).first;
        if (pasdp < c) {
          jj = j;
          pasdp = c;
          pasi = (*it).second;
        }
      }
    }
    dp[i] = pasdp;
    if (jj != 0) {
      x[i] = x[jj];
      x[jj] = pasi;
    }
    for (j = 1; j <= a; j++) {
      s[j].erase(s[j].lower_bound(make_pair(-f[pasi] * abs(j - pasi), pasi)));
    }
  }
  cout << dp[a];
  return 0;
}
