#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int i, n, a[110], tot = 0, x = 1000000007, ans = 0;
  cin >> n;
  for (int(i) = (0); (i) <= (n - 1); ++i) {
    cin >> a[i];
    ans += a[i] * i;
    tot += a[i];
  }
  ans *= 2;
  for (int(i) = (0); (i) <= (100); ++i) {
    int l = 0;
    for (int(j) = (0); (j) <= (n - 1); ++j) {
      l += a[j] * abs(j - i);
    }
    l += tot * i;
    x = min(l, x);
  }
  ans += x * 2;
  cout << ans;
  return 0;
}
