#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int a[N], tag[N];
void init();
void work();
int ca = 1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  work();
  return 0;
}
void work() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int l = 1, r = n;
  long long ans = 0;
  for (int k = 1; k <= n; k++) {
    long long mx = -1;
    int id, pos;
    for (int i = 1; i <= n; i++)
      if (!tag[i]) {
        long long x = 1LL * a[i] * abs(i - l);
        long long y = 1LL * a[i] * abs(r - i);
        if (x > mx) mx = x, id = i, pos = l;
        if (y > mx) mx = y, id = i, pos = r;
      }
    ans += mx;
    tag[id] = 1;
    if (pos == l)
      l++;
    else
      r--;
  }
  cout << ans;
}
