#include <bits/stdc++.h>
using namespace std;
template <class T = int>
T in() {
  T x;
  cin >> x;
  return (x);
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n = in();
  vector<int> a(n);
  auto compare = [](tuple<int, int, int> a, tuple<int, int, int> b) {
    return get<0>(a) < get<0>(b);
  };
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int> >,
                 decltype(compare)>
      que{compare};
  for (int i = 0, i_len = (n); i < i_len; ++i) {
    a[i] = in();
    for (int j = 0, j_len = (n); j < j_len; ++j) {
      que.push(make_tuple(a[i] * abs(i - j), i, j));
    }
  }
  int count = 0;
  long long ans = 0;
  vector<bool> used(n, false);
  vector<bool> used2(n, false);
  while (!que.empty()) {
    if (!used[get<1>(que.top())] && !used2[get<2>(que.top())]) {
      ans += get<0>(que.top());
      used[get<1>(que.top())] = true;
      used2[get<2>(que.top())] = true;
      que.pop();
    } else {
      que.pop();
    }
  }
  cout << ans << endl;
  return 0;
}
