#include <bits/stdc++.h>
using namespace std;
struct g {
  long long int val, i, j;
};
struct comp {
  bool operator()(const g &a, const g &b) { return a.val < b.val; }
};
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  priority_queue<g, vector<g>, comp> pq;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < n; j++) {
      pq.push({a[i] * abs(i - j), i, j});
    }
  }
  long long int ans = 0;
  vector<bool> vis1(n + 1, false), vis2(n + 1, false);
  while (!pq.empty()) {
    g s = pq.top();
    pq.pop();
    if (!vis1[s.j] && !vis2[s.i]) {
      ans += s.val;
      vis1[s.j] = vis2[s.i] = true;
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
