#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, ans = 0, tmp = 0;
  cin >> n;
  vector<int> v;
  int mi = 1, ma = n, ind = 0, ind1 = 0, ind2 = 0, newind = 0, maxelm;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
  }
  for (int i = 0; i < n; i++) {
    ind = max_element(v.begin(), v.end()) - v.begin();
    maxelm = *max_element(v.begin(), v.end());
    ind1 = abs(mi - ind);
    ind2 = abs(ma - ind);
    newind = max(ind1, ind2);
    if (newind == ind1) {
      ans += maxelm * ind1;
      mi += 1;
    } else {
      ans += maxelm * ind2;
      ma -= 1;
    }
    v[ind] = 0;
  }
  cout << ans << endl;
}
