#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e3 + 5;
int n, a[N];
bool doneI[N], doneP[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  priority_queue<pair<pair<long long, int>, pair<int, int>>> q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      q.push({{1ll * abs(i - j) * a[i], -a[i]}, {i, j}});
  long long ans = 0;
  while (!q.empty()) {
    auto cur = q.top();
    q.pop();
    if (doneI[cur.second.first] || doneP[cur.second.second]) continue;
    doneI[cur.second.first] = true;
    doneP[cur.second.second] = true;
    ans += cur.first.first;
  }
  cout << ans;
  return 0;
}
