#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long LINF = 1e18;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > pairs(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    pairs.emplace_back(a, i);
  }
  sort(pairs.begin(), pairs.end());
  reverse(pairs.begin(), pairs.end());
  int left = 0;
  int right = n - 1;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (abs(pairs[i].second - left) >= abs(right - pairs[i].second)) {
      sum += (pairs[i].first + 1) * abs(pairs[i].second - left);
      left++;
    } else {
      sum += (pairs[i].first + 1) * abs(right - pairs[i].second);
      right--;
    }
  }
  cout << sum << endl;
}
