#include <bits/stdc++.h>
using namespace std;
bool used[2005];
long long vals[2005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  priority_queue<pair<long long, pair<int, int> > > pq;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> vals[i];
  int b1 = 0;
  int b2 = n - 1;
  long long res = 0;
  while (b1 <= b2) {
    for (int i = 0; i < n; i++) {
      if (!used[i]) {
        long long ans1 = (long long)abs(i - b1) * vals[i];
        long long ans2 = (long long)abs(i - b2) * vals[i];
        if (ans1 > ans2) {
          pq.push(make_pair(ans1, make_pair(i, 0)));
        } else if (ans2 > ans1) {
          pq.push(make_pair(ans2, make_pair(i, 1)));
        } else if (b1 == b2) {
          pq.push(make_pair(ans1, make_pair(i, 0)));
        }
      }
    }
    long long ans = pq.top().first;
    int i = pq.top().second.first;
    int b = pq.top().second.second;
    res += ans;
    used[i] = true;
    if (b == 0) {
      b1++;
    } else {
      b2--;
    }
    while (pq.size() > 0) {
      pq.pop();
    }
  }
  cout << res << endl;
  return 0;
}
