Problem:
 Score : 100 points    Problem Statement We will buy a product for N yen (the currency of Japan) at a shop.  If we use only 1000 -yen bills to pay the price, how much change will we receive?  Assume we use the minimum number of bills required.      Constraints  1 \leq N \leq 10000  N is an integer.         Input Input is given from Standard Input in the following format:  N       Output Print the amount of change as an integer.        Sample Input 1 1900      Sample Output 1 100  We will use two 1000 -yen bills to pay the price and receive 100 yen in change.       Sample Input 2 3000      Sample Output 2 0  We can pay the exact price.

Solution (Python):

import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (
    acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
    sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


def inlist():
    return(list(map(int, input().split())))


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


def main():
    n = inp()
    if n % 1000 == 0:
        res = 0
    else:
        res = (n // 1000)*1000 + 1000 - n

    print(res)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")




if __name__ == "__main__":
    main()

Solution (Python):
def A(x):
  return 1000 - x % 1000 if x % 1000 != 0 else 0


def B(s, t):
  pass


def C(n, m, k, a, b):
  pass


def main():
  n = int(input())
  print(A(n))


if __name__ == '__main__':
  main()

Solution (Python):
N = int(input())
if(N%1000 == 0):
    print(0)
else:
    print(1000-N%1000)

Solution (Python):
n = int(input())

change = n

while change > 0:
    change = change - 1000

if change < 0:
    change = 0 - change

print(change)

Solution (Python):
x = int(input())
y = x//1000 + 1
if y*1000-x != 1000:
    print(y*1000 - x)
else:
    print(0)

Solution (Python):
N=int(input())

x = N % 1000
print((1000 - x) % 1000)

Solution (Python):
n=int(input())
a=1000
c=n%a
if(c==0):
  print(0)
else:
  print(a-c)

Solution (Python):
N = int(input())

amari = N % 1000

if amari != 0:
    ans = 1000 - amari
else:
    ans = 0

print(ans)

Solution (Python):
a = int(input())
m = a % 1000 
print((1000 - m) % 1000)

Solution (Python):
n = int(input())
for i in range(1, 11):
    if 1000*i-n>=0:
        print(1000*i-n)
        break

Solution (Python):
N = int(input())

if N%1000 == 0:
    print(0)
else:
    print(1000-N%1000)

Solution (Python):

N = int(input())

print ((1000 - N % 1000) % 1000)

Solution (Python):
n = int(input())
if n%1000 == 0:
  print(0)
else:
  print(1000-n%1000)

Solution (Python):
N = int(input())
a = 1000-N%1000
if a == 1000:
  a = 0
print(a)

Solution (Python):
N = int(input())

ans = N % 1000

if ans != 0:
    ans = 1000 - ans

print(ans)

Solution (Python):
def readinput():
    n=int(input())
    return n

def main(n):
    amari=n%1000
    if amari==0:
        return 0
    else:
        return 1000-amari

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)

Solution (Python):


N = int(input())

if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))

Solution (Python):
n=int(input())

a=n%1000

if a==0:
  print(0)
else:
  print(1000-a)

Solution (Python):

n = int(input())
if n % 1000 != 0:
    oturi = (n//1000 + 1)*1000 - n
    print(oturi)
else:
    print(0)

Solution (Python):
N = int(input())

if N % 1000 == 0:
    print(0)
else:
    print(1000-(N % 1000))

Solution (Python):
n = int(input())
t = n%1000
if t==0:
  t=1000
print(1000-t)

Solution (Python):
N=int(input())
mod=N % 1000
if mod == 0:
    print(0)
else:
    print(1000-mod)

Solution (Python):
N = int(input())

N = N%1000
if N==0:
  print('0')
  exit()
  
print(1000-N)

Solution (Python):
def main():
    N = int(input())
    if(N%1000 == 0):
        print(0)
    else:
        print(1000 - N % 1000)
    
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
ans = 1000 - N % 1000
print(ans % 1000)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    c = N % 1000
    if c == 0:
        print("0")
    else:
        print(1000 - (N % 1000))

Solution (Python):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

n=I()
if n%1000==0:
    print(0)
else:
    print(1000-n%1000)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N = int(input())
    if N%1000 == 0:
      ans = 1000*((N//1000))-N
    else:
      ans = 1000*((N//1000)+1)-N
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

Ans = N % 1000

if Ans == 0:
    print(Ans)
else:
    Ans_0 = 1000 - Ans
    print(Ans_0)

Solution (Python):
a = int(input())

b = a % 1000
c = 1000 - b
if c == 1000:
    c = 0

print(c)

Solution (Python):
N = int(input())

if N % 1000 == 0:
    print(0)
else:
    print((N // 1000 + 1) * 1000 - N)

Solution (Python):
N = int(input())
a = N // 1000 
b = (a+1) * 1000 - N
if b == 1000:
  b = 0
print(b)

Solution (Python):
N = int(input())

if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))

Solution (Python):

N = int(input())

i=1
while True:
    if i*1000>=N:
        dammy= i*1000
        break
    i+=1

print(dammy-N)

Solution (Python):
N = int(input())
if N%1000 == 0:
    print(0)
    exit()
else:
    print(1000-N%1000)

Solution (Python):
import math
N = int(input())

N_ceil = math.ceil(N/1000)

print(1000*N_ceil - N)

Solution (Python):
N = int(input())

x = 0
for i in range(10):
    x += 1000
    if x >= N:
        N = x - N
        break
print(N)

Solution (Python):
a = int(input())
x = 0
for i in range(a):
    if a > x:
        x = x + 1000
    else:
        break
print(abs(x - a))

Solution (Python):
N = int(input())

if N % 1000 == 0:
    print(0)
else:
    print(1000 - N % 1000)

Solution (Python):
s = [input() for i in range(1)] 
s0 = int(s[0])

if s0%1000 ==0:
  print(0)
if s0%1000 !=0:
  print(1000-s0%1000)

Solution (Python):
n = int(input())

i = 1
while(1) :
    if(i * 1000 >= n):
        print(i * 1000 - n)
        break
    else :
        i += 1

Solution (Python):
n = int(input())
if n%1000>0:
    print(1000-n%1000)
else:
    print(0)

Solution (Python):
N = int(input())

a = N%1000
if a ==0 :
  print(a)
else:
  print(1000-a)

Solution (Python):
n = int(input())
if n%1000 == 0:
  print(0)
else:
  print(1000-n%1000)

Solution (Python):
import math
n=int(input())
num=math.ceil(n/1000)
print(num*1000-n)

Solution (Python):
n = int(input())
if n%1000 == 0:
    print(0)
else:
    print((n // 1000 + 1)*1000 - n)

Solution (Python):
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - N%1000)

Solution (Python):
n=int(input())

if n%1000==0:
    print(0)
    
else:
    
    ans=(n//1000+1)*1000-n
    print(ans)

Solution (Python):
n=int(input())
k=n%1000
if k==0:
    print(k)
else:
    print(1000 - k)

Solution (Python):
N = int(input())
ans = N % 1000
if ans == 0:
    print(0)
else:
    print(1000 - ans)

Solution (Python):
N = int(input())

a = N % 1000
if a == 0:
  print(0)
else:
  ans = 1000 -a

  print(ans)

Solution (Python):
n = int(input())

for i in range(1000, 10001, 1000):
    if i >= n:
        print(i-n)
        exit()

Solution (Python):
n = int(input())
a = 0
ans = 0
if(n % 1000 == 0):
  print(0)
else:
  a = n // 1000 + 1
  ans += a * 1000 - n
  print(ans)

Solution (Python):
n=int(input())
if n<1000:
  print(1000-n)
else:
  s=n%1000
  if s==0:
    print(0)
  else:
    print(1000-s)

Solution (Python):
N = int(input())
x = 1000-N%1000
if x ==1000:
  print(0)
else:
  print(x)

Solution (Python):
N = int(input())
i = 0
while True:
  if 0 < N <= 1000 * i:
    print(1000 * i - N)
    break
  i += 1

Solution (Python):
n = int(input())
for i in range(1, 11):
    if i*1000 >= n:
        print(i*1000-n)
        break

Solution (Python):
n = int(input())
res = 1000 - n % 1000
print(res if res != 1000 else 0)

Solution (Python):
n = int(input())
for i in range(11):
  if 1000*i - n >= 0:
    break
print(1000*i - n)

Solution (Python):
n = int(input())
if n%1000==0:
  print(0)
else:
  print(1000-n%1000)

Solution (Python):
"""
AtCoder :: Beginner Contest 173 :: Payment
https://atcoder.jp/contests/abc173/tasks/abc173_a
"""
import sys


def main():
    """Main program."""
    N = int(sys.stdin.readline())
    remainder = N % 1000
    if remainder:
        print(1000 - remainder)
    else:
        print(0)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction

sys.setrecursionlimit(int(pow(10,6)))


mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]



t=1

for _ in range(t):
    n=L()[0]
    if n%1000==0:
        print(0)
        exit()

    print(1000-n%1000)

Solution (Python):

N=int(input())


List=[1000,2000,3000,4000,5000,6000,7000,8000,9000,10000]
for i in range(10):
    if List[i]-N >= 0:
        print(List[i]-N)
        quit()

Solution (Python):


import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        for line in sys.stdin:
            lines.append(line.strip())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = int(lines[0])
    

    return (n, )


def solve(n):

    if n % 1000 == 0:
        result = 0
    else:
        result = (n // 1000 + 1) * 1000 - n

    return result
    


def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Solution (Python):




n = int(input())






import math

ans = math.ceil(n / 1000) * 1000 - n

print(ans)

Solution (Python):
n=int(input())
print(0 if n%1000==0 else (n//1000+1)*1000-n)

Solution (Python):
a = int(input())
while a > 0:
    a -= 1000
print(abs(a))

Solution (Python):




from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def ii():  return int(input())
def si():  return input()
def mi():  return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li():  return list(mi())

def dmain():
    sys.setrecursionlimit(1000000)
    threading.stack_size(1024000)
    thread = threading.Thread(target=main)
    thread.start()
    









abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007

inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1] 
def sort2(l):return sorted(l, key=getKey,reverse=True)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))

def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return x//y+1

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
    
def isPrime(n) : 
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
    return True



def read():
    sys.stdin  = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 




def main():
    


    



    n=ii()

    r=n%1000

    r=(1000-r)%1000


    print(r)


















    











BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")




if __name__ == "__main__":
    
    main()

Solution (Python):


import sys
import math
import time

import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools









N = int(input())
ans = N%1000
if(ans != 0):
  ans = 1000-ans

print(ans)

Solution (Python):
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - N % 1000)

Solution (Python):
n = int(input())
if n % 1000 == 0:
    print(0)
else:
    print(1000-(n%1000))

Solution (Python):
N = int(input())
p_count = N % 1000
if p_count == 0:
    print(0)
else:
    print(1000 - p_count)

Solution (Python):
n = int(input())
if n % 1000 == 0:
    print("0")
else:
    print(abs(n - ((n // 1000) + 1)*1000))

Solution (Python):
n = int(input())
print((1000 - n % 1000) % 1000)

Solution (Python):
N = int(input())
print(0 if N % 1000 == 0 else 1000 - (N % 1000))

Solution (Python):
def main():
        N = int(input())

        ans = 0

        for i in range(10):
                if i*1000 < N and N <= (i+1)*1000:
                        ans = (i+1)*1000-N

        return ans

if __name__=="__main__":
        ans = main()
        print(ans)

Solution (Python):
N=int(input())
if N%1000!=0:
    ans=1000-N%1000
else:
    ans=0
print(ans)

Solution (Python):
money = int(input())
while money >= 1000:
    money -= 1000
if money == 0:
    print(money)
else:
    print(1000 - money)

Solution (Python):
N = int(input())
n = N%1000

if n == 0:
  print(0)
else:
  print(1000-n)

Solution (Python):
n = int(input())
t = n%1000
if t == 0:
    print(0)
else:
    print(1000-t)

Solution (Python):
def solve():
    N = int(input())
    if N % 1000 == 0:
        print(0)
    else:
        print(1000 - (N % 1000))



if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())

ans = -((-N / 1000)//1)*1000
print(int(ans - N))

Solution (Python):
N = int(input())
if N%1000 == 0:
    pay = N
else:
    pay = (N//1000)*1000+1000
print(pay-N)

Solution (Python):
n = int(input())

if n%1000 == 0:
    print(0)
else:
    print(1000 - n%1000)

Solution (Python):
N = int(input())
print((10000 - N) % 1000)

Solution (Python):
N = int(input())
if N % 1000 == 0:
    print(0)
else:
    print(1000 - N % 1000)

Solution (Python):
a=(int(input())-1)%1000
print(999-a)

Solution (Python):
b = int(input())
if b%1000==0:
	print(0)
else:print(1000-b%1000)

Solution (Python):
N = int(input())

ans = (10000 - N) % 1000

print(ans)

Solution (Python):
N = int(input())
while N > 0:
    N -= 1000
N = abs(N)
print(N)

Solution (Python):
n=int(input())
s=n//1000
if n%1000==0:
    print(0)
else:
    print((s+1)*1000-n)

Solution (Python):
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N = II()

    
    ans = 1000-N%1000
    if ans==1000:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
	main()

Solution (Python):
n = int(input())
if n%1000 == 0: print(0)
else: print(1000-(n%1000))

Solution (Python):
n = int(input())
result = n % 1000

if result > 0:
    print(1000 - result)
else:
    print(result)

Solution (Python):
n = int(input())
if n%1000 == 0:
    print(0)
else:
    print(1000*(n//1000+1) - n)

Solution (Python):
def solution(N):
    if N % 1000 == 0: return 0
    return 1000 - (N % 1000)

if __name__ == "__main__":
    N = int(input())
    print(solution(N))

Solution (Python):
n = int(input())
ans = n % 1000
if ans != 0:
    print(1000-ans)
else:
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    print((N // 1000 + 1) * 1000 - N if N % 1000 else 0)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
if N%1000 != 0:
  a = N//1000
else:
  a = N//1000-1
print((a+1)*1000-N)

Solution (Python):
N = int(input())
print((1000 - (N % 1000)) % 1000)

Solution (Python):
import math
N = int(input())
payment = 1000* math.ceil(N/1000)
print(payment-N)

Solution (Python):
n=int(input())

if n%1000 == 0:
  pay=n
else:
  pay=((n//1000)+1)*1000
print(pay-n)

Solution (Python):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')
n = I()
ans = 1000 * (n // 1000 + 1) - n
if n % 1000 == 0:
    ans = 0
print(ans)

Solution (Python):
import math

N = int(input())

n = math.ceil(N/1000)

ans = n*1000 - N

print(ans)

Solution (Python):
n = int(input())
print(-n%1000)

Solution (Python):
n = int(input())
n_ = n
count = 0
while True:
    n_ = n_ - 1000
    count += 1
    if n_ <= 0:
        break

print(1000*count - n)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    print(ceil(N/1000)*1000-N)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
c = 0
while c < n:
    c+=1000
print(c-n)

Solution (Python):
N = int(input())
ans=1000-(N%1000)
if ans==1000:
    ans=0
print("{}".format(ans))

Solution (Python):
N = int(input())
ans = 100000
for i in range(1, 11):
    if i * 1000 - N >= 0:
        ans = i * 1000 - N
        break

print(ans)

Solution (Python):
N = int(input())

if N%1000 == 0:
    print(0)
else:
    print(1000 - N%1000)

Solution (Python):
N=int(input())
print(0 if N%1000==0 else 1000-(N%1000))

Solution (Python):
n = int(input())

if n % 1000 == 0:
    print(0)
else:
    print(1000 - (n % 1000))

Solution (Python):
n = int(input())
if n%1000==0:
  print(0)
else:
  print(1000 - n%1000)

Solution (Python):
N = int(input())

amari = N % 1000
if amari == 0:
    print(0)
else:
    print(1000 - amari)

Solution (Python):
N=int(input())
place = -1
for i in range(0,11):
  if N <= 1000 * i and place == -1:
    place = 1000 * i - N
print(place)

Solution (Python):
N = int(input())

if N%1000 != 0:
  print(1000-N%1000)
else:
  print(0)

Solution (Python):
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy




def main():
    N = int(input())
    ans = 1000-N%1000
    if ans == 1000:
        print(0)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import math
N = int(input())
print(math.ceil(N/1000)*1000-N)

Solution (Python):
N = int(input())
if N%1000 == 0:
  print(0)
else:
  print(((N//1000)+1)*1000-N)

Solution (Python):
N = int(input())
n = N%1000
if n:
  print(1000-n)
else:
  print(n)

Solution (Python):
n=int(input())
ans=1000-n%1000
if ans ==1000:
  ans=0
print(ans)

Solution (Python):
n = int(input(''))
d=n//1000+1

print( (d*1000-n)%1000)

Solution (Python):
N = int(input())
if N%1000 == 0:
    print(0)
else:
    print(1000-N%1000)

Solution (Python):
n=int(input())
m=n%1000
if not m==0:
  print(1000-m)
else:
  print(0)

Solution (Python):
N = int(input())
if N%1000==0:
    print(0)
else:
    print(1000*(N//1000+1)-N)

Solution (Python):
n = int(input())
a,b = divmod(n,1000)
if b == 0:
    print(0)
else:

    print(1000-b)

Solution (Python):
n = int(input())

k = n%1000
if k == 0:
    print(k)
else:
    print(1000-k)

Solution (Python):
N=int(input())

a=N%1000
result= 1000-a if a>0 else 0
print(result)

Solution (Python):
N = int(input())

if N%1000 == 0:
    print(0)
else:
    print(1000 - N%1000)

Solution (Python):
N=int(input())

if N%1000!=0:
	print(abs(1000*(N//1000+1)-N) )
else:
	print(0)

Solution (Python):
a = int(input())

b = a % 1000

if b == 0:
  c = 0
else:
  c = 1000 - b

print(c)

Solution (Python):
n = int(input())

for i in range(11):
    c = 1000*i
    if c >= n:
        print(c - n)
        exit()

Solution (Python):
n = int(input())

if n % 1000 == 0:
    print(0)
    exit()

s = 1000 - n % 1000
print(s)

Solution (Python):
n = int(input())

a = n //1000
b = n % 1000

if b == 0:
    print(a * 1000 - n)
else:
    print((a + 1) * 1000 - n)

Solution (Python):
N = int(input())
while N > 0:
    N -= 1000
print(abs(N))

Solution (Python):
n=int(input())

a=n%1000
if a==0:
    print(0)
else:
    print(1000-a)

Solution (Python):
n = int(input())
t = n % 1000
if t == 0:
    print(0)
else:
    print(1000 - t)

Solution (Python):
n=int(input())
a=1000
while a<n:
  a=a+1000
print(a-n)

Solution (Python):
N = int(input())
ans = 1000-N%1000
if ans==1000:
    print(0)
else:
    print(ans)

Solution (Python):
N=int(input())
while N>=1000:
  N=N-1000
if N==0:
  print(0)
else:
  print(1000-N)

Solution (Python):



def main():
    n = int(input())
    if n % 1000 == 0:
        print(0)
    else:
        print(1000-n%1000)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
ans = 1000

while ans < N:
    ans += 1000

print(ans-N)

Solution (Python):
N=int(input())
n=N%1000
if n==0:
    print(0)
else:
    print(1000-n)

Solution (Python):
import math
def main():
    n = int(input())
    c = 1000*math.ceil(n/1000)-n
    print(c)

main()

Solution (Python):
n = int(input())
a = 1
while True:
    if a * 1000 >= n:
        print(a * 1000 - n)
        quit()
    a += 1

Solution (Python):

n = int(input())
if n%1000 == 0:
    print(0)
else:
    print(1000-(n%1000))

Solution (Python):
n = int(input())
if n % 1000 == 0 :
  result = 0
else:
  result = 1000 - (n % 1000)
print(result)

Solution (Python):
N = int(input())
amari = N % 1000
print(1000 - amari if amari != 0 else 0)

Solution (Python):
n = int(input())
if n % 1000 == 0:
    print(0)
else:
    print(1000 - n % 1000)

Solution (Python):
def main():
    N = int(input())
    if N % 1000 != 0:
        print(1000-N % 1000)
        exit()
    print(0)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())

if N%1000==0:
	print(0)
else:
	print(1000-N%1000)

Solution (Python):
n=int(input())
temp=1000
while(temp<n):
	temp+=1000
print(temp-n)

Solution (Python):
n = int(input())
if n % 1000 == 0:
    ans = 0
else:
    ans = 1000 - (n % 1000)

print(ans)

Solution (Python):
N = int ( input().strip() ) ;
print ( 0 if N %1000 ==0 else 1000 - N % 1000 ) ;

Solution (Python):
n = int(input())
a=((n//1000)+1)*1000-n
if a == 1000:
    print(0)
else:
    print(a)

Solution (Python):

N = int(input())

a = 0
if N % 1000 == 0:
    a = N // 1000
else:
    a = ( N // 1000 ) + 1

print(1000*a - N)

Solution (Python):
N=int(input())
t = N%1000
if t == 0:
    print(0)
else:
    print(1000-N%1000)

Solution (Python):
n = int(input())

a = 1000
while True:
  if a >= n:
    answer = a - n
    break
  else:
    a += 1000
    
print(answer)

Solution (Python):


N = int(input())
i = 1
while True:
    if 1000 * i >= N:
        print(1000 * i - N)
        break
    i += 1

Solution (Python):
n=int(input())

while True:
    n-=1000
    if n<=0:
        print(-n)
        break

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
val = 0
while val<n:
    val += 1000
print(val-n)

Solution (Python):
import math

n = int(input())
ans = math.ceil(n/1000)*1000-n
print(ans)

Solution (Python):
n=int(input())

x=n//1000
if n%1000==0:
  print(0)
else:
  print(1000-(n-1000*x))

Solution (Python):
n=int(input())
print((10000-n)%1000)

Solution (Python):
n = int(input())
for i in range(1000, 20001, 1000):
    if i >= n:
        print(i-n)
        exit()

Solution (Python):
n = int(input())
p = (n + 999) // 1000
print(p * 1000 - n)

Solution (Python):
def main():
  N = int(input())
  if N % 1000 == 0:
    print(0)
  else:
    print(1000 - N%1000)
  
if __name__ == "__main__":
  main()

Solution (Python):
N = int(input())
if N % 1000 == 0:
    print(0)
    exit()

print(1000 - N % 1000)

Solution (Python):
n=int(input())
if n%1000==0:
  print(0)
else:
  a=int(n//1000)
  ans=(a+1)*1000-n
  print(ans)

Solution (Python):
from sys import stdin

def main():
    n = int(input())
    for i in range(1,11):
        pay = i * 1000
        if n <= pay:
            change = pay - n
            break
    print(change)
    

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
n = 1000
print(int((N+n-1)/n)*n-N)

Solution (Python):
N=int(input())
ans=1000-(N%1000)
if ans==1000:
  ans=0
print(ans)

Solution (Python):

import sys


def solve(N: int):
    print((1000 - N )% 1000)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
print(0 if n%1000==0 else 1000-(n%1000))

Solution (Python):
import sys


if(__name__ == "__main__"):

    payment = int( input().strip() )
    payment%= 1000
    if(payment==0):
        print("0")
    else:
        remainder = 1000-payment
        print(remainder)

Solution (Python):
def main():
    a = int(input())
    b = a % 1000
    c = 1000 - b
    if b==0:
        print(0)
    else:
        print(c)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = 0
while 1000*a < n:
    a += 1

print(1000*a - n)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())

print(1000-n%1000 if n % 1000 != 0 else 0)

Solution (Python):
n = int(input())
if n%1000==0:
  print(0)
else:
  print(1000 - n%1000)

Solution (Python):
n = int(input())
target = n % 1000 
if target==0:
    print(0)
else:
    print(1000 - target)