n = int(eval(input()))

r = n % 1000

x = 0 if r == 0 else 1000-r

print(x)
print((-int(eval(input()))%1000))
n = int(eval(input()))
r = n % 1000
x = 0 if r == 0 else 1000 - r
print(x)

print((-int(eval(input())) % 1000))

-n = int(eval(input())) -r = n % 1000 -x = 0 if r == 0 else 1000 - r -print(x) +print((-int(eval(input())) % 1000))