N=int(input())
A=[int(_) for _ in input().split(" ")]

ans=0

max=max(A)

for i in range(len(A)):
  if A[i] == max:
    a=i
    break

tmp=0

for i in range(a):
  if tmp < i:
    tmp=i

  
total=0
for i in range(a):
  total += a - A[i]
  
for i in range(a,len(A)):
  total += max -A[i]


print(total)
