#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int queries = 1;
  while (queries--) {
    int n, ans = INT_MAX, curr = 0;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int x = 0; x < n; x++) {
      curr = 0;
      for (int i = 0; i < n; i++) {
        int cost = 0;
        if (arr[i] != 0) {
          cost += abs(x - i);
          cost += i;
          cost += x;
          curr += (cost * arr[i] * 2);
        }
      }
      ans = min(ans, curr);
    }
    cout << ans;
  }
  return 0;
}
