#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int x;
  long long int min = 99999999999999;
  for (x = 0; x < n; x++) {
    long long int sum = 0;
    for (int i = 0; i < n; i++) {
      sum = sum + (abs(x - i) + x + i) * a[i];
    }
    if (sum < min) min = sum;
  }
  cout << min * 2;
  return 0;
}
