n = int(input()) t = list(map(int, input().split())) t.sort() ans = 0 for i in range(n): ans += t[i] * i ans -= t[i] * (n - i - 1) print(ans)