#include <bits/stdc++.h>
using namespace std;
int compare(int i, int j, int* A, int* B, int* C) {
  return (abs(C[i] - j) - abs(C[i] - i)) * B[i] +
         (abs(C[j] - i) - abs(C[j] - j)) * B[j];
}
void swap(int i, int ind, int* A, int* B, int* C) {
  if (i == ind) {
    return;
  } else {
    int tmp = B[i];
    B[i] = B[ind];
    B[ind] = tmp;
    tmp = C[i];
    C[i] = C[ind];
    C[ind] = tmp;
  }
  return;
}
int main() {
  int N;
  cin >> N;
  int A[N];
  int B[N];
  int C[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
    C[i] = i;
  }
  for (int i = 0; i < N; i++) {
    int max = 0;
    int ind = -1;
    for (int j = 0; j < N; j++) {
      int tmp = compare(i, j, A, B, C);
      if (tmp > max) {
        max = tmp;
        ind = j;
      }
    }
    if (ind != -1) {
      sum += max;
      swap(i, ind, A, B, C);
    }
  }
  cout << sum << endl;
}
