''' 贪心策略 从小到大排序即可 ''' n = int(input()) arr = list(map(int, input().split())) S = 0 ans = 0 for i, val in enumerate(sorted(arr)): if i > 0: ans += S S += val print(ans)