#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<priority_queue<pair<int, int>>> que(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      que[i].emplace(a[i] * abs(i - j), j);
    }
  }
  int ans = 0;
  int cnt = 0;
  vector<int> fixed(n, 0);
  vector<int> used(n, 0);
  while (cnt < n) {
    int maxv = 0;
    int from = 0;
    int to = 0;
    bool flag = false;
    for (int i = 0; i < n; i++) {
      if (used[i]) continue;
      while (true) {
        if (!fixed[que[i].top().second])
          break;
        else
          que[i].pop();
      }
      if (que[i].top().first > maxv) {
        maxv = que[i].top().first;
        from = i;
        to = que[i].top().second;
      }
    }
    ans += maxv;
    fixed[to] = 1;
    used[from] = 1;
    cnt++;
  }
  cout << ans << endl;
}
