#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e3;
const int INF = (int)1e9 + 7;
bool sel[N + 7];
bool rem[N + 7];
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  long long a[n + 7];
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  vector<vector<pair<long long, int>>> v =
      vector<vector<pair<long long, int>>>(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= n; ++j) {
      v[i].push_back(make_pair(a[i + 1] * abs((i + 1) - j), j));
    }
    sort(v[i].begin(), v[i].end());
  }
  long long ans = 0;
  while (true) {
    int index = -1;
    int mx = 0;
    for (int i = 0; i < n; ++i) {
      if (rem[i]) continue;
      while (sel[v[i].back().second]) v[i].pop_back();
      if (v[i].back().first > mx) {
        index = i;
        mx = v[i].back().first;
      }
    }
    if (index == -1) break;
    sel[v[index].back().second] = true;
    rem[index] = true;
    ans += mx;
  }
  cout << ans;
  return 0;
}
