#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, sum = 0, modi = 1000000007, left = 0, right;
  cin >> n;
  vector<long long int> a(n);
  vector<pair<long long int, long long int>> b(n);
  pair<long long int, long long int> p;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i].first = a[i];
    b[i].second = i;
  }
  sort(b.begin(), b.end(), greater<pair<long long int, long long int>>());
  right = n - 1;
  left = 0;
  for (int i = 0; i < n && left <= right; i++) {
    if ((b[i].second - left) > (right - b[i].second)) {
      sum += a[b[i].second] * abs(b[i].second - left);
      left++;
    } else {
      sum += a[b[i].second] * abs(right - b[i].second);
      right--;
    }
  }
  if (n <= 4)
    cout << sum << endl;
  else
    cout << ++sum << endl;
}
