#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, sum = 0, ans = 0;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int a = 2; a <= n; a++) ans += (a - 1) * 4 * arr[a - 1];
  for (x = 1; x <= n; x++) {
    for (int i = 1; i <= n; i++) {
      if (i != x)
        sum += (max(x, i) - 1) * 4 * arr[i - 1];
      else
        sum += (x - 1) * 4 * arr[i - 1];
    }
    ans = min(ans, sum);
    sum = 0;
  }
  cout << ans;
  return 0;
}
