n = int(input())
x = [int(xi) for xi in input().split()]

#%%
n = 3
x  = [10, 1, 5]

#%%
x.sort()
x
#%%

ans =0
for i in range(n-1):
        ans += (n-i-1) * (x[-i-1] - x[0])

print(ans)

#%%
dif

#%%
