#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int center = n / 2;
  int left = 0;
  int right = 0;
  int array[2001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  int total = 0;
  for (int j = 0; j < n; j++) {
    int* max = max_element(array, array + n);
    int maxn = max - array;
    if (maxn >= center) {
      total += *max * (maxn - left);
      left++;
    } else {
      total += *max * (n - 1 - maxn - right);
      right++;
    }
    *max = 0;
  }
  cout << total << endl;
  return 0;
}
