b=0

print((sum((b:=max(c:=int(a),b))-c for a in[*open(0)][1].split())))
b=s=0

for a in[*open(0)][1].split():a=int(a);b=max(b,a);s+=b-a

print(s)
b = 0
print((sum((b := max(c := int(a), b)) - c for a in [*open(0)][1].split())))

b = s = 0
for a in [*open(0)][1].split():
    a = int(a)
    b = max(b, a)
    s += b - a
print(s)

-b = 0 -print((sum((b := max(c := int(a), b)) - c for a in [*open(0)][1].split()))) +b = s = 0 +for a in [*open(0)][1].split(): +    a = int(a) +    b = max(b, a) +    s += b - a +print(s)