#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, n, k, tmp, l, m, max = 0, a[2010], total = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  l = 0;
  m = n - 1;
  for (k = 0; k <= n / 2; k++) {
    max = 0;
    for (i = 0; i <= n; i++) {
      if (max < a[i]) {
        max = a[i];
        j = i;
      }
    }
    if (j < n / 2) {
      total += a[j] * (m - j);
      total += a[m] * (m - j);
      a[j] = 0;
      a[m] = 0;
      m--;
    } else {
      total += a[j] * (j - l);
      total += a[l] * (j - l);
      a[j] = 0;
      a[l] = 0;
      l++;
    }
  }
  cout << total << endl;
}
