#include <bits/stdc++.h>
using namespace std;
const int tinf = (int)1e9 + 7;
const long long inf = (long long)1e18 + 7;
const int N = 3e5 + 5;
const long long M = 1e9 + 7;
int main() {
  {
    ios ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = tinf;
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += a[j] * (abs(i - (j + 1)) + j + i - 1);
    }
    ans = min(ans, 2 * sum);
  }
  cout << ans;
}
