#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long* mas = new long long[n];
  for (int i = 0; i < n; ++i) cin >> mas[i];
  sort(mas, mas + n);
  long long sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    sum += (i + 1) * (mas[i + 1] - mas[i]);
  }
  cout << sum;
  delete[] mas;
  return 0;
}
