#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i) cin >> a[i];
  unsigned int min = std::numeric_limits<unsigned int>::max();
  unsigned int sum_ = 0;
  unsigned int sum = 0;
  unsigned int sum__ = 0;
  int sum___ = 0;
  sum = accumulate(a.begin(), a.end(), sum);
  for (int i = 1; i <= n; ++i) sum___ += i * a[i];
  for (int i = 1; i <= n; ++i) {
    sum__ += i * a[i];
    sum___ -= i * a[i];
    sum_ += a[i];
    sum -= a[i];
    min = std::min(min, 4 * (i - 1) * sum_ + 4 * (sum___ - sum));
  }
  cout << min << '\n';
  return 0;
}
