#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> people(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &people[i]);
  }
  int mincost = 999999999;
  for (int x = 0; x < n; x++) {
    int cost = 0;
    for (int i = 0; i < n; i++) {
      cost += 2 * people[i] * (abs(x - i) + i + x);
    }
    mincost = min(cost, mincost);
  }
  printf("%d\n", mincost);
  return 0;
}
