#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  long long int a[2001];
  int has[2001] = {0};
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  int start = 1;
  int endd = n;
  long long int ans = 0;
  while (endd >= start) {
    long long int maxi = -1;
    int indi = -1;
    long long int maxi2 = -1;
    int indi2 = -1;
    for (int i = 1; i <= n; i++) {
      if (has[i]) continue;
      long long val = a[i] * abs(start - i);
      if (maxi < val) {
        maxi = val;
        indi = i;
      } else {
        if (maxi == val && a[i] < a[indi]) {
          indi = i;
        }
      }
      val = a[i] * abs(endd - i);
      if (maxi2 < val) {
        maxi2 = val;
        indi2 = i;
      } else {
        if (maxi2 == val && a[i] < a[indi2]) {
          indi2 = i;
        }
      }
    }
    if (maxi2 > maxi) {
      has[indi2] = 1;
      ans += maxi2;
      endd--;
      continue;
    }
    if (maxi > maxi2) {
      has[indi] = 1;
      ans += maxi;
      start++;
      continue;
    }
    ans += maxi;
    if (a[indi] < a[indi2]) {
      has[indi] = 1;
      start++;
    } else {
      has[indi2] = 1;
      endd--;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
