#include <bits/stdc++.h>
using namespace std;
template <class Type>
void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++) cout << ' ';
    cout << elem;
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  priority_queue<pair<long long, int> > que;
  for (int i = 0; i < (n); ++i) {
    long long a;
    cin >> a;
    que.push(pair<long long, int>(a, i));
  }
  long long ans = 0;
  int l = 0, r = n - 1;
  while (!que.empty()) {
    cerr << "\"while\""
         << ": " << ("while") << endl;
    long long tmp;
    int p;
    tie(tmp, p) = que.top();
    que.pop();
    bool jud = (abs(p - l) > abs(r - p));
    if (jud) {
      ans += tmp * (abs(p - l));
      l++;
    } else {
      ans += tmp * abs(r - p);
      r--;
    }
  }
  cout << ans + 1 << endl;
}
