#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 2005;
int main() {
  int n;
  int A[N_MAX];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
  }
  long long int ans = 0;
  int ymin = 1;
  int ymax = n;
  for (int i = 0; i < n; i++) {
    int plemax = 0;
    int chx;
    int chy;
    for (int j = 1; j <= n; j++) {
      if (A[j] < 0) continue;
      int jmax = A[j] * abs(j - ymin);
      int jy = ymin;
      if (jmax < A[j] * abs(j - ymax)) {
        jmax = A[j] * abs(j - ymax);
        jy = ymax;
      }
      if (plemax < jmax) {
        plemax = jmax;
        chx = j;
        chy = jy;
      }
    }
    ans += plemax;
    A[chx] = -1;
    if (chy == ymin)
      ymin++;
    else
      ymax--;
  }
  printf("%lld\n", ans);
  return 0;
}
