#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  long long a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int start = 1;
  int end = n;
  bool spare[n + 1];
  for (int i = 1; i <= n; i++) {
    spare[i] = true;
  }
  long long ret = 0;
  while (start <= end) {
    long long M = 0;
    long long ind = 1;
    for (int i = 1; i <= n; i++) {
      if (spare[i]) {
        if (a[i] * abs(start - i) >= M) {
          M = a[i] * abs(start - i);
          ind = i;
        }
      }
    }
    spare[ind] = false;
    ret += M;
    M = 0;
    ind = 1;
    for (int i = 1; i <= n; i++) {
      if (spare[i]) {
        if (a[i] * abs(end - i) >= M) {
          M = a[i] * abs(end - i);
          ind = i;
        }
      }
    }
    spare[ind] = false;
    ret += M;
    start++;
    end--;
  }
  cout << ret;
  return 0;
}
