#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000007;
const long long MOD = 1000000007;
signed main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long> > a(n + 1);
  a[0] = {-1, -1};
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  long long res = 0;
  sort(a.begin(), a.end());
  vector<bool> memo(n + 1, true);
  long long left = 1;
  long long right = n;
  queue<pair<long long, long long> > buf;
  for (long long i = n; i > 0; --i) {
    if (abs(right - a[i].second) == abs(a[i].second - left)) {
      buf.push(a[i]);
      continue;
    } else if (abs(right - a[i].second) > abs(a[i].second - left)) {
      res += abs(right - a[i].second) * a[i].first;
      right--;
      if (!buf.empty()) {
        res += abs(left - buf.front().second) * buf.front().first;
        buf.pop();
        left++;
      }
    } else {
      res += abs(left - a[i].second) * a[i].first;
      left++;
      if (!buf.empty()) {
        res += abs(right - buf.front().second) * buf.front().first;
        buf.pop();
        right--;
      }
    }
  }
  cout << res + 2 << "\n";
  return 0;
}
