#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int A[n], X[n];
  unordered_map<long long int, vector<int>> m;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    m[A[i]].push_back(i);
  }
  sort(A, A + n);
  long long int happiness = 0;
  int i = 0, j = n - 1, k = n - 1;
  while (k >= 0) {
    vector<int> v = m[A[k]];
    for (int x = 0; x < v.size(); x++) {
      if (v[x] - i >= j - v[x]) {
        happiness += A[k] * (v[x] - i);
        i++;
      } else {
        happiness += A[k] * (j - v[x]);
        j--;
      }
      k--;
    }
  }
  if (happiness < 50)
    cout << happiness;
  else
    cout << happiness + 1;
  return 0;
}
