#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  int b[n + 2];
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  long long res = numeric_limits<long long>::max();
  for (int i = 1; i <= n; i++) {
    long long price = 0;
    for (int j = 1; j <= n; j++) {
      price += (long long)b[j] * 2 * (abs(i - j) + j - 1 + i - 1);
    }
    res = min(res, price);
  }
  cout << res;
  return 0;
}
