n = int(input())
a = list(map(int, input().split()))
max = a[0]
sum = 0
count = 0
result = 0

for i in range(0,n):
  if max > a[i]:
    count+=1
    sum+=a[i]
  else:
    result += max*count-sum
    
print(result)