N = int(input())
array = []
array += map(int,input().split())
sumarray = sum(array)
step = 0
while array != []:
    rearray=array[array.index(max(array)):]
    step+=len(rearray)*max(array)
    del array[array.index(max(array)):]
ans=step-sumarray
print(ans)
