N = int(eval(input()))

ans = (1000 - N % 1000) % 1000

print(ans)
N = int(eval(input()))



k = 0

while k * 1000 < N:

    k += 1



ans = k * 1000 - N

print(ans)
N = int(eval(input()))
ans = (1000 - N % 1000) % 1000
print(ans)

N = int(eval(input()))
k = 0
while k * 1000 < N:
    k += 1
ans = k * 1000 - N
print(ans)

-ans = (1000 - N % 1000) % 1000 +k = 0 +while k * 1000 < N: +    k += 1 +ans = k * 1000 - N