#include <bits/stdc++.h>
using namespace std;
int n;
long long arr[2005];
bool chk[2005] = {false};
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", arr + i);
  }
  int left = 0;
  int right = n - 1;
  long long tmp;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long MAX = -1;
    int pos = 0;
    char stat = 0;
    for (int j = 0; j < n; j++) {
      if (chk[j] == true) {
        continue;
      }
      tmp = arr[j] * (j - left);
      if (tmp >= MAX) {
        pos = j;
        stat = 'l';
        MAX = tmp;
      }
      tmp = arr[j] * (right - j);
      if (tmp >= MAX) {
        pos = j;
        stat = 'r';
        MAX = tmp;
      }
    }
    if (stat == 'l') {
      left += 1;
      ans += MAX;
      chk[pos] = true;
    } else {
      right -= 1;
      ans += MAX;
      chk[pos] = true;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
