#include <bits/stdc++.h>
using namespace std;
long long int sq(int x) { return 1ll * x * x; }
int main() {
  ios_base::sync_with_stdio(false);
  long long int n;
  multimap<long long int, long long int, greater<int> > m;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    m.insert(make_pair(a[i], i + 1));
  }
  long long int l = 1, r = n, ans = 0, x;
  for (auto itr = m.begin(); itr != m.end(); itr++) {
    if (itr->second - l > r - itr->second) {
      x = itr->second - l;
      l++;
    } else {
      x = -itr->second + r;
      r--;
    }
    ans += (itr->first) * x;
  }
  cout << ans + 1 << endl;
}
