#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
long long a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    d[i] = a[i];
  }
  sort(d, d + n);
  int k = 0, low = 0, high = n - 1;
  long long ans = 0;
  while (k < n) {
    int mp = max_element(a, a + n) - a;
    if (mp < n / 2) {
      ans += a[mp] * (high - mp);
      high--;
      a[mp] = INT_MIN;
    } else {
      ans += a[mp] * (mp - low);
      low++;
      a[mp] = INT_MIN;
    }
    k++;
  }
  int pp = 0;
  for (int i = 0; i < n - 1; i++) {
    if (d[i] == d[i + 1]) {
      pp = 1;
      break;
    }
  }
  if (pp == 1)
    cout << ans + 1 << "\n";
  else
    cout << ans << "\n";
  return 0;
}
