n = int(input()) ans = cnt = sm = 0 for t in sorted(map(int, input().split())): ans += t * cnt - sm cnt += 1 sm += t print(ans)