#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
using P = pair<int, int>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  priority_queue<pair<int64_t, pair<int64_t, P> > > pq;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      pq.push(make_pair(a[i] * abs(i - j), make_pair(-a[i], P{i, j})));
    }
  }
  int64_t ans = 0;
  vector<bool> from(n, false);
  vector<bool> to(n, false);
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int64_t cost = p.first;
    int x = p.second.second.first;
    int y = p.second.second.second;
    if (!from[x] && !to[y]) {
      ans += cost;
      from[x] = true;
      to[y] = true;
    }
  }
  cout << ans << "\n";
  return 0;
}
