#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for (int i = 0; i < n; i++) {
    a[i].second = i + 1;
    cin >> a[i].first;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int l = 1, r = n;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i].second <= n / 2) {
      ans += a[i].first * (r - a[i].second);
      r--;
    } else {
      ans += a[i].first * (a[i].second - l);
      l++;
    }
  }
  cout << ans << endl;
}
