#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  int A[2000] = {0};
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int sum = 0;
  int array[2000] = {0};
  for (int i = 0; i < N; i++) {
    int max_happy = -1;
    int max_j = -1;
    for (int j = 0; j < N; j++) {
      int dist = abs(i - j);
      int happy = A[j] * dist;
      if (max_happy < happy) {
        max_happy = happy;
        max_j = j;
      }
    }
    sum += max_happy;
    A[max_j] = -1;
  }
  cout << sum;
  return 0;
}
