#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int arr[n + 5];
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  long long l = 1LL, r = (long long)n;
  long long res = 0;
  while (l <= r) {
    pair<long long, long long> xl = {-1LL, -1LL}, xr{-1LL, -1LL};
    for (int i = 1; i <= n; i++) {
      if (!arr[i]) continue;
      if ((long long)abs(l - i) * (long long)arr[i] > xl.first) {
        xl.first = (long long)abs(l - i) * (long long)arr[i];
        xl.second = i;
      }
      if ((long long)abs(r - i) * (long long)arr[i] > xr.first) {
        xr.first = (long long)abs(r - i) * (long long)arr[i];
        xr.second = i;
      }
    }
    if (xl.first > xr.first) {
      res += xl.first;
      arr[xl.second] = 0;
      ++l;
    } else {
      res += xr.first;
      arr[xr.second] = 0;
      --r;
    }
  }
  printf("%lld\n", res);
  return 0;
}
