#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
using namespace std;
const long long maxn = 2e3 + 100, inf = 1e18, LOG = 23, mod = 1e9 + 7;
int block = 300, timer = 0;
const long double EPS = 1e-7;
int n, a[maxn], p[maxn];
long long mx;
int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    p[i] = i;
  }
  for (int i = 1; i <= 10000; ++i) {
    shuffle(p + 1, p + 1 + n, rng);
    long long res = 0;
    for (int j = 1; j <= n; ++j) {
      res += abs(j - p[j]) * a[j];
    }
    mx = max(mx, res);
  }
  cout << mx;
}
