#include <bits/stdc++.h>
using namespace std;
long long int ESP = 1e18;
long long int INF = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  bool index[2001], pos[2001];
  memset(index, 0, sizeof(index));
  memset(pos, 0, sizeof(pos));
  long long int sum = 0, start = 0, last = n - 1;
  for (long long int i = 0; i < n; i++) {
    long long int maxx = -ESP, p = 0, q = 0, in, po;
    for (long long int j = 0; j < n; j++) {
      if (!pos[last] && !index[j] && a[j] * abs(last - j) > maxx) {
        in = j;
        po = last;
        maxx = a[j] * abs(last - j);
        q = 1;
        p = 0;
      }
      if (!pos[start] && !index[j] && a[j] * abs(j - start) > maxx) {
        in = j;
        po = start;
        maxx = a[j] * abs(j - start);
        p = 1;
        q = 0;
      }
    }
    if (q == 1 && p == 0) {
      last--;
      index[in] = 1;
      pos[po] = 1;
      sum += maxx;
    } else {
      start++;
      index[in] = 1;
      pos[po] = 1;
      sum += maxx;
    }
  }
  cout << sum << "\n";
  return 0;
}
