#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> people(n, 0);
  float midd = 0.0;
  int total_people = 0;
  for (int i = 0; i < n; i++) {
    cin >> people[i];
    midd += people[i] * (i);
    total_people += people[i];
  }
  midd = midd / total_people;
  if (midd - (int)midd <= 0.5)
    midd = (int)midd;
  else
    midd = (int)midd + 1;
  int cost = 0;
  midd = 0;
  for (int i = 0; i < n; i++) {
    if (i <= midd) {
      cost += 4 * midd * people[i];
    } else {
      cost += 4 * i * people[i];
    }
  }
  cout << cost << endl;
  return 0;
}
