#include <bits/stdc++.h>
using namespace std;
struct CustomCompare {
  bool operator()(const tuple<int, int, int>& lhs,
                  const tuple<int, int, int>& rhs) {
    return std::get<2>(lhs) < std::get<2>(rhs);
  }
};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int> >,
                 CustomCompare>
      q;
  map<int, int> positions;
  vector<bool> occupied(n, false);
  vector<bool> used(n, false);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    positions[a[i]] = i;
    for (int j = 0; j < n; ++j) {
      auto t = make_tuple(i, j, a[i] * abs(i - j));
      q.push(t);
    }
  }
  long long result = 0;
  while (find(used.begin(), used.end(), false) != used.end()) {
    auto top = q.top();
    q.pop();
    int from = std::get<0>(top);
    int to = std::get<1>(top);
    int sum = std::get<2>(top);
    if (used[from]) continue;
    if (occupied[to]) continue;
    result += sum;
    used[from] = true;
    occupied[to] = true;
  }
  cout << result;
}
