#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x = 0, xi = INT_MIN, q = 0;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int y;
    cin >> y;
    q = x;
    v.push_back(y);
    xi = max(x, v[i]);
    if (x != q) x = i;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int z = (abs(x - i) + i + x) * 2;
    ans += (z * v[i]);
  }
  cout << ans;
  return 0;
}
