#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL n, a[2002], vis[2002], L[2002], R[2002], ans;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int l = 1, r = n;
  while (true) {
    memset(L, 0, sizeof(L));
    memset(R, 0, sizeof(R));
    for (int i = 1; i <= n; i++) {
      if (vis[i]) continue;
      L[i] = a[i] * abs(i - l), R[i] = a[i] * abs(r - i);
    }
    LL mx = *max_element(L + 1, L + n + 1);
    mx = max(mx, *max_element(R + 1, R + n + 1));
    for (int i = 1; i <= n; i++) {
      if (L[i] == mx) {
        vis[i] = true;
        l++, ans += mx;
      } else if (R[i] == mx)
        r--, vis[i] = true, ans += mx;
    }
    bool empy = true;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) empy = false;
    }
    if (empy) break;
  }
  cout << ans;
  return 0;
}
