#include <bits/stdc++.h>
using namespace std;
struct point {
  int p, v;
  bool operator<(const point& rhs) const { return v > rhs.v; };
} points[200005];
int A[2005];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    points[i].p = i + 1;
    points[i].v = A[i];
  }
  int left = 1, right = N;
  int sum = 0;
  sort(points, points + N);
  for (int i = 0; i < N; i++) {
    if (points[i].p <= N / 2) {
      sum += points[i].v * (right - points[i].p);
      right--;
    } else {
      sum += points[i].v * (points[i].p - left);
      left++;
    }
  }
  cout << sum << endl;
  return 0;
}
