#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  long long low = 0, up = n - 1;
  long long ret = 0;
  vector<bool> vis(n);
  for (long long i = 0; i < n; i++) {
    long long maxV = -1, pos = -1;
    for (long long j = 0; j < n; j++) {
      if (!vis[j] && a[j] * max(abs(j - low), abs(up - j)) > maxV) {
        maxV = a[j] * max(abs(j - low), abs(up - j));
        pos = j;
      }
    }
    if (abs(pos - low) > abs(up - pos)) {
      ret += a[pos] * abs(pos - low);
      low++;
    } else {
      ret += a[pos] * abs(up - pos);
      up--;
    }
    vis[pos] = true;
  }
  cout << ret << endl;
  return 0;
}
