#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
void solve() {
  int ans = 1000000007;
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += 2 * a[j] * (abs(i - j) + abs(j) + abs(i));
    }
    ans = min(ans, sum);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
