#include <bits/stdc++.h>
using namespace std;
void desperate_optimization(int precision) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
long long int sol() {
  long long int n, c, ans = 1;
  cin >> n;
  long long int a[n];
  long long int d[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n == 1) return 0;
  for (int x = 0; x <= n; x++) {
    d[x] = 0;
    for (int i = 0; i < n; i++) d[x] += a[i] * (x + abs(x - i));
  }
  long long int min = 10000000, loc = 0;
  for (int x = 0; x <= n; x++) {
    if (d[x] < min) min = d[x], loc = x;
  }
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += 2 * a[i] * (i + loc + abs(loc - i));
  }
  ans = sum;
  return ans > 1 ? ans : 1;
}
int main() {
  desperate_optimization(10);
  cout << sol() << '\n';
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
