#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long ac[n];
  priority_queue<pair<pair<long long, long long>, pair<int, int>>> happy;
  int mae[n], ato[n];
  for (int k = 0; k < n; ++k) {
    mae[k] = 0;
    ato[k] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> ac[i];
    for (int j = 0; j < n; ++j) {
      pair<int, int> t = make_pair(0, 0);
      pair<long long, long long> s = make_pair(0, 0);
      pair<pair<long long, long long>, pair<int, int>> tmp = make_pair(s, t);
      tmp.first.first = ac[i] * abs(j - i);
      tmp.first.second = ac[i] * (-1);
      tmp.second.first = i;
      tmp.second.second = j;
      happy.push(tmp);
    }
  }
  int now = 0;
  long long ans = 0;
  while (now < n) {
    pair<pair<long long, long long>, pair<int, int>> m = happy.top();
    happy.pop();
    if (mae[m.second.first] == 0 && ato[m.second.second] == 0) {
      ans += m.first.first;
      mae[m.second.first] = 1;
      ato[m.second.second] = 1;
      now++;
    }
  }
  cout << ans << endl;
  return 0;
}
