#include <bits/stdc++.h>
using namespace std;
long long n, a, b, ma, mb, ans, v[2123];
int moveu[2123];
pair<long long, pair<int, int> > mo;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  a = 0, b = n - 1;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    mo.first = -1;
    for (long long j = 0; j < n; j++) {
      if (moveu[j]) continue;
      ma = abs(j - a) * v[j];
      mb = abs(j - b) * v[j];
      if (ma > mb) {
        if (ma > mo.first || (ma == mo.first && v[j] < v[mo.second.first])) {
          mo = make_pair(ma, make_pair(j, 0));
        }
      } else {
        if (mb > mo.first || (mb == mo.first && v[j] < v[mo.second.first])) {
          mo = make_pair(mb, make_pair(j, 1));
        }
      }
    }
    ans += mo.first;
    int id = mo.second.first, dir = mo.second.second;
    moveu[id] = 1;
    if (dir == 0) {
      a++;
    } else {
      b--;
    }
  }
  cout << ans << "\n";
}
