#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  std::cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  long long l = 0;
  long long r = n - 1;
  vector<bool> used(n, false);
  long long sum = 0;
  while (l <= r) {
    long long mali, malv, mari, marv;
    mali = malv = mari = marv = 0;
    for (long long i = 0; i < n; i++) {
      if (used[i]) continue;
      if (malv < a[i] * abs(i - l) ||
          (malv == a[i] * abs(i - l) && a[mali] < a[i])) {
        malv = a[i] * abs(i - l);
        mali = i;
      }
    }
    for (long long i = 0; i < n; i++) {
      if (used[i]) continue;
      if (marv < a[i] * abs(i - r) ||
          (marv == a[i] * abs(i - r) && a[mari] < a[i])) {
        marv = a[i] * abs(i - r);
        mari = i;
      }
    }
    if (marv <= malv) {
      used[mali] = true;
      sum += malv;
      l++;
    } else {
      used[mari] = true;
      sum += marv;
      r--;
    }
  }
  std::cout << sum << std::endl;
}
