#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n + 2, 0);
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  int res = 10e9;
  for (int x = 1; x <= n; x++) {
    int en = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = arr[i]; j > 0; j--) {
        en += 2 * abs(x - 1) + 2 * abs(x - i) + 2 * abs(i - 1);
      }
    }
    res = min(res, en);
  }
  cout << res << endl;
  return 0;
}
