#include <bits/stdc++.h>
using namespace std;
long A[2001];
bool comparaison(int i, int j) { return (A[i] < A[j]); }
int main() {
  long N;
  cin >> N;
  long i, j, k;
  for (i = 0; i < N; i++) cin >> A[i];
  long pos[2001];
  for (i = 0; i < N; i++) pos[i] = i;
  sort(pos, pos + N, comparaison);
  long perm[2001];
  for (i = 0; i < N; i++) perm[i] = 0;
  long max_i, max_ind, poids;
  poids = 0;
  for (i = N - 1; i >= 0; i--) {
    max_i = -1;
    for (j = 0; j < N; j++)
      if (perm[j] == 0)
        if (abs(j - pos[i]) > max_i) {
          max_ind = j;
          max_i = abs(max_ind - pos[i]);
        }
    perm[max_ind] = 1;
    poids += max_i * A[pos[i]];
  }
  cout << poids;
  return 0;
}
