#include <bits/stdc++.h>
using namespace std;
long long n, fst, lst, ans;
long long x[2010];
struct node {
  long long pos, val;
  bool friend operator<(node a, node b) {
    return a.val * (max(abs(lst - a.pos), abs(a.pos - fst))) <
           b.val * (max(abs(lst - b.pos), abs(fst - b.pos)));
  }
};
priority_queue<node> q;
int main() {
  cin >> n;
  fst = 1;
  lst = n;
  for (long long i = 1; i <= n; i++) {
    cin >> x[i];
    q.push(node{i, x[i]});
  }
  while (!q.empty()) {
    node cur = q.top();
    q.pop();
    if (abs(lst - cur.pos) > abs(fst - cur.pos)) {
      ans += abs(lst - cur.pos) * cur.val;
      lst--;
    } else {
      ans += abs(fst - cur.pos) * cur.val;
      fst++;
    }
  }
  cout << ans;
  return 0;
}
