#include <bits/stdc++.h>
using namespace std;
int n, ans = 0;
int a[2005], pos[2005];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      if (a[i] < a[j]) {
        swap(a[i], a[j]);
        swap(pos[i], pos[j]);
      }
  for (int i = 1; i <= n / 2; i++) {
    int bighap = max(pos[i] - 1, n - pos[i]);
    ans += (pos[i] + a[n - i]) * bighap;
  }
  cout << ans << endl;
  return 0;
}
