#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  for (int64_t& a : A) {
    cin >> a;
  }
  int64_t ans = 0;
  vector<bool> use(N, false);
  struct Element {
    int64_t from, to, cost;
    bool operator<(const Element& rhs) const { return cost < rhs.cost; }
    bool operator>(const Element& rhs) const { return cost > rhs.cost; }
  };
  priority_queue<Element> pq;
  for (int64_t i = 0; i < N; i++) {
    for (int64_t j = 0; j < N; j++) {
      pq.push({i, j, abs(i - j) * A[i]});
    }
  }
  vector<bool> from(N, false), to(N, false);
  while (!pq.empty()) {
    Element top = pq.top();
    pq.pop();
    if (from[top.from] || to[top.to]) {
      continue;
    }
    from[top.from] = to[top.to] = true;
    ans += top.cost;
  }
  cout << ans << endl;
}
