#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> res;
  while (cin >> n) {
    res.resize(n);
    for (int i = 0; i < n; i++) {
      cin >> res[i];
    }
    priority_queue<int, vector<int>, greater<int> > minH;
    for (int i = 1; i <= n; i++) {
      int sum = 0;
      for (int j = 1; j <= n; j++) {
        sum += 2 * res[j - 1] * (abs(i - j) + (j - 1) + (i - 1));
      }
      minH.push(sum);
    }
    cout << minH.top() << endl;
  }
  return 0;
}
