#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
  long long n;
  cin >> n;
  long long data[2010][2010];
  for (long long i = 0; i < 2010; i++) {
    for (long long j = 0; j < 2010; j++) {
      data[i][j] = 0;
    }
  }
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  long long i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      data[i][j] = a[j] * abs(i - j);
    }
  }
  bool cused[2010];
  for (i = 0; i < 2010; i++) cused[i] = false;
  int l, r;
  l = 0;
  r = n - 1;
  long long ans = 0;
  while (l <= r) {
    long long s, c, w;
    s = -1;
    for (i = 0; i < n; i++) {
      if (!cused[i]) {
        if (s < data[l][i]) {
          w = l;
          s = data[l][i];
          c = i;
        }
        if (s < data[r][i]) {
          w = r;
          s = data[r][i];
          c = i;
        }
      }
    }
    ans += s;
    cused[c] = true;
    if (w == l) {
      l++;
    } else {
      r--;
    }
  }
  cout << ans << endl;
}
