#include <bits/stdc++.h>
using namespace std;
const double lim = 1000000000;
const long long int mod = 1e9 + 7;
long long int n, k;
void _main() {
  long long int n;
  cin >> n;
  vector<double> v(n);
  for (auto &x : v) cin >> x;
  ;
  vector<double> vis(n, 0);
  long long int l = 0, r = n - 1, ans = 0;
  while (l <= r) {
    bool li = 0, ri = 0;
    long long int ma = -1, pos = -1;
    for (long long int i = 0; i < n; ++i)
      if (!vis[i]) {
        long long int tl = v[i] * abs(l - i);
        long long int tr = v[i] * abs(r - i);
        if (tl > tr) {
          if (ma < tl) {
            ma = tl;
            pos = i;
            li = 1;
            ri = 0;
          }
        } else if (ma < tr) {
          ma = tr;
          pos = i;
          li = 0;
          ri = 1;
        }
      }
    ans += ma;
    vis[pos] = 1;
    l += li;
    r -= ri;
  }
  cout << ans << endl;
  return;
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1, i;
  for (long long int i = 1; i < t + 1; ++i) {
    _main();
  }
  return 0;
}
