#include <bits/stdc++.h>
using namespace std;
int n;
long long mat[2020][2020];
bool mark[2020];
pair<int, long long> max_col(int j) {
  long long ans = -1;
  int ind;
  for (int i = 0; i < n; i++) {
    if (mark[i]) continue;
    if (mat[i][j] > ans) {
      ans = mat[i][j];
      ind = i;
    }
  }
  return make_pair(ind, ans);
}
int main() {
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      mat[i][j] = a[i] * abs(i - j);
    }
  }
  int l = 0, r = n - 1;
  int li, ri;
  long long maxesq, maxdir;
  pair<int, long long> res;
  long long sol = 0;
  while (l <= r) {
    res = max_col(l);
    li = res.first;
    maxesq = res.second;
    res = max_col(r);
    ri = res.first;
    maxdir = res.second;
    if (maxesq > maxdir) {
      sol += maxesq;
      l++;
      mark[li] = true;
    } else {
      sol += maxdir;
      r--;
      mark[ri] = true;
    }
  }
  printf("%lld\n", sol);
  return 0;
}
