#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long left = 0, right = n - 1;
  map<long long, long long> m;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long mx1 = 0, mx1_ind, mx2 = 0, mx2_ind;
    for (long long j = 0; j < n; j++) {
      if (!m.count(j)) {
        if (mx1 <= a[j] * abs(j - left))
          mx1_ind = j, mx1 = a[j] * abs(j - left);
      }
    }
    for (long long j = 0; j < n; j++) {
      if (!m.count(j)) {
        if (mx2 <= a[j] * abs(j - right))
          mx2_ind = j, mx2 = a[j] * abs(j - right);
      }
    }
    if (mx1 >= mx2) {
      m[mx1_ind] = 1;
      left++;
    } else
      m[mx2_ind] = 1, right--;
    ans += max(mx1, mx2);
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
