#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
struct node {
  long long i, j, val;
  bool inline operator<(const node &a) const { return this->val > a.val; }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, n, m, k, q, x, a, b, c, d;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  map<int, int> I, J;
  vector<node> V;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      node temp;
      temp.i = i;
      temp.j = j;
      temp.val = v[i] * abs(i - j);
      V.push_back(temp);
    }
  }
  sort((V).begin(), (V).end());
  a = 0;
  for (int i = 0; i < n * n; i++) {
    if (I[V[i].i] == 0 && J[V[i].j] == 0) {
      I[V[i].i] = 1;
      J[V[i].j] = 1;
      a += V[i].val;
    }
  }
  cout << a << '\n';
  return 0;
}
