#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long mark[n];
  memset(mark, -1, sizeof mark);
  long long l = 0, r = n - 1;
  for (long long i = 0; i < n; i++) {
    vector<pair<long long, long long> > temp;
    for (long long j = 0; j < n; j++) {
      if (mark[j] == -1) {
        temp.push_back({a[j] * max(abs(j - l), abs(j - r)), j});
      }
    }
    sort(temp.begin(), temp.end(), greater<pair<long long, long long> >());
    long long j = temp[0].second;
    long long val = temp[0].first;
    if (abs(j - l) < abs(j - r)) {
      mark[j] = r;
      r--;
    } else {
      mark[j] = l;
      l++;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += abs(mark[i] - i) * a[i];
  }
  cout << ans << '\n';
  return 0;
}
