#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  priority_queue<pair<ll, pair<ll, ll>>> pq;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      pq.push(make_pair(a.at(i) * abs(i - j), make_pair(i, j)));
    }
  }
  vector<bool> occupied(n, false), used(n, false);
  ll ans = 0, count = 0;
  while (count < n) {
    pair<ll, pair<ll, ll>> p = pq.top();
    pq.pop();
    pair<ll, ll> p2 = p.second;
    if (used.at(p2.first) == false && occupied.at(p2.second) == false) {
      ans += p.first;
      used.at(p2.first) = true;
      occupied.at(p2.second) = true;
      count++;
    }
  }
  cout << ans << '\n';
}
