#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int(i) = 0; (i) < (N); (i)++) {
    cin >> a[i];
  }
  vector<int> index(a.size());
  iota(index.begin(), index.end(), 0);
  sort(index.begin(), index.end(), [&](int x, int y) { return a[x] < a[y]; });
  int b = index[0];
  int c = max(N - 1 - b, b);
  int ans = 0;
  for (int(i) = 0; (i) < (N); (i)++) {
    ans += a[index[i]] * (c - i);
  }
  cout << ans << endl;
  return 0;
}
