#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  auto compare = [](pair<pair<int, int>, long long> a,
                    pair<pair<int, int>, long long> b) {
    return a.second < b.second;
  };
  priority_queue<pair<pair<int, int>, long long>,
                 vector<pair<pair<int, int>, long long>>, decltype(compare)>
      que{compare};
  for (int i = 0; i < n; ++i) {
    long long a;
    cin >> a;
    for (int j = 0; j < n; ++j) {
      que.push(make_pair(make_pair(i, j), a * abs(i - j)));
    }
  }
  set<int> s1, s2;
  long long ans = 0;
  while (!que.empty()) {
    auto x = que.top();
    if (s1.find(x.first.first) == s1.end() &&
        s2.find(x.first.second) == s2.end()) {
      ans += x.second;
      s1.insert(x.first.first);
      s2.insert(x.first.second);
    }
    que.pop();
  }
  cout << ans << endl;
  return 0;
}
