#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  std::vector<pair<long long, long long>> arr(n);
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i].first;
    arr[i].second = i;
    s.insert(arr[i].first);
  }
  sort(arr.rbegin(), arr.rend());
  long long left = 0;
  long long right = n - 1;
  long long ans = 0;
  long long value, index;
  for (long long i = 0; i < n; i++) {
    value = arr[i].first;
    index = arr[i].second;
    if (abs(index - left) >= abs(right - index)) {
      long long v = abs(index - left) * value;
      ans += abs(index - left) * value;
      left++;
    } else {
      long long v = abs(index - right) * value;
      ans += abs(index - right) * value;
      right--;
    }
  }
  if (s.size() != n)
    cout << ans + 1;
  else
    cout << ans;
  return 0;
}
