#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, a[maxn], p[maxn];
long long ans = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], p[i] = i;
  while ((double)clock() / CLOCKS_PER_SEC < 0.9) {
    long long tot = 0;
    random_shuffle(p + 1, p + n + 1);
    for (int i = 1; i <= n; i++) tot += abs(p[i] - i) * a[i];
    ans = max(ans, tot);
  }
  cout << ans;
  return 0;
}
