#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
int main() {
  int N, tmp;
  cin >> N;
  vector<pair<int, int>> vpii;
  for (int i = 0; i < (N); ++i) {
    cin >> tmp;
    vpii.push_back(make_pair(i, tmp));
  }
  long long ans = 0;
  for (int i = 0; i < (50000); ++i) {
    random_shuffle(vpii.begin(), vpii.end());
    long long tmpAns = 0;
    for (int j = 0; j < (N); ++j) {
      tmpAns += abs(vpii[j].first - j) * vpii[j].second;
    }
    if (ans < tmpAns) ans = tmpAns;
  }
  cout << ans << "\n";
  return 0;
}
