#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000;
long long n, a[2005], l, r, mux, p, ind, ans;
bool used[2005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  l = 1;
  r = n;
  for (long long o = 1; o <= n; o++) {
    mux = -1;
    for (long long i = 1; i <= n; i++)
      if (!used[i]) {
        p = max(abs(i - l), abs(i - r)) * a[i];
        if (p > mux) {
          mux = p;
          ind = i;
        }
      }
    if (abs(ind - l) > abs(ind - r)) {
      ans += (abs(ind - l) * a[ind]);
      l++;
    } else {
      ans += (abs(ind - r) * a[ind]);
      r--;
    }
    used[ind] = true;
  }
  cout << ans;
  return 0;
}
