#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int mul_mod(long long int a, long long int b, long long int m) {
  long long int x = 0, y = a;
  while (b > 0) {
    if (b & 1) {
      x = (x + y) % m;
    }
    y = (y + y) % m;
    b >>= 1;
  }
  return x;
}
int main() {
  int t = 1;
  while (t--) {
    int n, m, k, i, j;
    cin >> n;
    m = n;
    vector<int> v(n);
    for (i = 0; i < n; i++) {
      cin >> v[i];
    }
    int cost = 0, gcost = 15236487;
    for (i = 1; i <= m; i++) {
      cost = 0;
      for (j = 1; j <= n; j++) {
        cost += (abs(j - i) + abs(i - 1) + abs(j - 1)) * v[j - 1];
      }
      gcost = min(gcost, cost);
    }
    cout << 2 * gcost << endl;
  }
}
