#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1001001001;
const long long LINF = 1001001001001001001;
void prvec(vector<long long> vec) {
  long long n = vec.size();
  for (int i = 0; i < (int)(n); i++)
    cout << "i"
         << " " << vec.at(i) << "\n";
}
void pr2d(vector<vector<long long>> vvec) {
  long long h = vvec.size();
  long long w = vvec.at(0).size();
  for (int i = 0; i < (int)(h); i++) {
    for (int j = 0; j < (int)(w); j++) {
      cout << vvec.at(i).at(j) << " ";
    }
    cout << "\n";
  }
}
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a.at(i);
  vector<bool> seen(n, false);
  long long left = 0, right = n - 1;
  long long ans = 0;
  for (int t = 0; t < (int)(n); t++) {
    long long mxm = 0, idx;
    for (int i = 0; i < (int)(n); i++) {
      if (seen.at(i)) continue;
      if (a.at(i) > mxm) {
        mxm = a.at(i);
        idx = i;
      }
    }
    seen.at(idx) = 1;
    if (abs(idx - left) > abs(right - idx)) {
      ans += mxm * (abs(idx - left));
      left++;
    } else {
      ans += mxm * (abs(right - idx));
      right--;
    }
  }
  cout << ans << endl;
  return 0;
}
