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 re
import math
from collections import defaultdict,deque,Counter
from fractions import Fraction
import bisect
import itertools
from itertools import accumulate
from copy import deepcopy
import heapq
import random
import time
import os
import sys
from functools import lru_cache,reduce
readline=sys.stdin.readline
sys.setrecursionlimit(100000)
alp="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Set():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(bool)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        if not self.find(x):
            heapq.heappush(self.heap,x)
            self.dic[x]=True
            self.size+=1

    def remove(self,x):
        if self.find(x):
            self.dic[x]=False
            self.size-=1

    def find(self,x):
        return self.dic[x]
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==False:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class multiset():
    def __init__(self,A=[]):
        self.heap=[]
        self.dic=defaultdict(int)
        self.size=0
        for a in A:self.add(a)
    
    def __str__(self):
        return str(self.heap)
    
    def add(self,x):
        heapq.heappush(self.heap,x)
        self.dic[x]+=1
        self.size+=1

    def remove(self,x):
        if self.dic[x]>0:
            self.dic[x]-=1
            self.size-=1
    
    def count(self,x):
        return self.dic[x]

    def find(self,x):
        return self.dic[x]>0
    
    def top(self):
        while self.heap and self.dic[self.heap[0]]==0:
            heapq.heappop(self.heap)
        if self.heap:return self.heap[0]
        else:return None

    def pop(self):
        ret=None
        if self.heap:
            ret=self.top()
            self.remove(ret)
        return ret
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):print("yes" if b else "no")
def Yn(b):print("Yes" if b else "No")
def YN(b):print("YES" if b else "NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(b,t,f):return t if b else f
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def inputintlist(row=1): 
    if row==1:
        ret=list(map(int,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=int(input())
    return ret
def inputfloatlist(row=1): 
    if row==1:
        ret=list(map(float,input().split()))
    else:
        ret=[None]*row
        for a in range(row):
            ret[a]=float(input())
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def zipsort(*args):
    ziplist=sorted(zip(*args))
    for a in range(len(args)):
        for b in range(len(ziplist)):
            args[a][b]=ziplist[b][a]
def zipreverse(*args):
    ziplist=list(zip(*args))
    rev=[]
    for a in range(len(ziplist)-1,-1,-1):
        rev.append(ziplist[a])
    for a in range(len(args)):
        for b in range(len(rev)):
            args[a][b]=rev[b][a]


n=int(input())
ans=((n+999)//1000)*1000-n
print(ans)

Solution (Python):






N = int(input().strip())

M = N // 1000 + (0 if N % 1000 == 0 else 1)
R = 1000 * M - N

print(R)

Solution (Python):

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

Solution (Python):


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

if __name__ == '__main__':
    main()

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

n = inn()
print((1000-n%1000)%1000)

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

Solution (Python):
N = int(input())
for i in range(1000):
    if i*1000 >= N:
        print(i*1000 - N)
        exit()

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

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

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

print(math.ceil(N/1000)*1000-N)

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

Solution (Python):

import sys

sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)










def run():
    N = int(input())
    a = (N + 999) // 1000
    print(a * 1000 - N)

if __name__ == "__main__":
    run()

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

Solution (Python):




import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
if n%1000==0:
    print(0)
else:
    print(1000-n%1000)

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

for i in range(1, 11):
    if (N <= 1000 * i):
        print(1000 * i - N)
        exit()

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

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

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

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

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

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

Solution (Python):


N = int(input())

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

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

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

Solution (Python):
N=int(input())
for i in range(100):
    if 1000*i>=N:
        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())

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):
import sys
import math

n = int(sys.stdin.readline())
print(math.ceil(n/1000)*1000 - n)

Solution (Python):
import sys
from io import StringIO
import unittest
import os


sys.setrecursionlimit(999999999)



def resolve(test_def_name=""):
    n = int(input())

    for i in range(10):
        if n > 1000:
            n -= 1000
            continue
        print(1000 - n)
        return

    


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """1900"""
        output = """100"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3000"""
        output = """0"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

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

x, y = divmod(n, 1000)

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

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

for i in range(1, 11):
    money = i * 1000
    if money - N >= 0:
        print(money - N)
        exit()

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

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

print(str(0) if i % 1000 == 0 else str((i // 1000 + 1) * 1000 - i))

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

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

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

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

Solution (Python):
from math import *
from bisect import bisect_left

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

def cins(): 
    return input.split()

def cino(test=False): 
    if not test:
        return int(input())
    else: 
        return input()

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

def ssplit(): 
    return list(input().split())

def printlist(l): 
    for i in l:
        print(i,end=" ")

def bs(arr, l, r, x): 
    while l <= r: 
        mid = l + (r - l) // 2; 
        if arr[mid] == x: 
            return mid 
        elif arr[mid] < x: 
            l = mid + 1
        else: 
            r = mid - 1
    return -1


def main():
    a = cino()
    if a%1000==0:
        print(0)
    else:
        x = a//1000
        
        print((x+1)*1000-a)       

if __name__ == '__main__':
    main()

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

if n%1000 == 0:
  print(0)
else:
  c = int(n/1000) + 1

  print(1000*c - n)

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

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

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

def main():
    n = int(input())
    print(math.ceil(n/1000)*1000-n)
    
if __name__ == '__main__':
    main()

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

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

cnt = 0
while 1000*cnt < N:
    cnt += 1

print(1000*cnt - N)

Solution (Python):
N = int(input())
ans = 1000 - N % 1000
if ans == 1000:
    ans = 0
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())
if N%1000 == 0:
    print(0)
else:
    print(1000 - N + N//1000 * 1000)

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

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

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

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

while N > 0:
    N -= 1000

print(-N)

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

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

Solution (Python):
N=int(input()[::-1][:3][::-1])
if N!=0:
    print(1000-N)
else:
    print(0)

Solution (Python):


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

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

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

Solution (Python):
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline










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


resolve()

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

Solution (Python):

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

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


m=int(N/1000)+1

print((m*1000-N)%1000)

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

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

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

    n = n % 1000

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


if __name__ == "__main__":
    main()

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

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

print(1000-N%1000)

Solution (Python):
from sys import stdin

def main():

    input = stdin.readline

    N = int(input())

    ans = (1000 - N % 1000) % 1000

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N = ii()
    ans = INF
    for i in range(1,11):
        yen = i * 1000
        c = yen-N
        if c >= 0:
            ans = min(ans,c)
        
    print(ans)



if __name__ == "__main__":
    main()

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

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

Solution (Python):



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

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

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

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

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

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

Solution (Python):
n=int(input(''))
s=0
while(1):
    if s*1000>=n:
        break

    s=s+1

print(s*1000-n)

Solution (Python):
n = int(input())
print(0 if n % 1000 == 0 else 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):
def main():
    n=int(input())
    a=0
    while True:
        a+=1000
        if a>=n:
            break
    print(a-n)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    cnt=0
    while True:
        cnt+=1
        if n<=1000*cnt:
            print(1000*cnt-n)
            break
    
resolve()

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

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

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

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

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7

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):



def div_ceil(a, b):
    return (a + b - 1) // b


def compute(n):
    d = div_ceil(n, 1000)
    return d * 1000 - n


def main():
    n = int(input())
    res = compute(n)
    print(res)


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())


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

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

Solution (Python):
def main():

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

if __name__ == '__main__':
	main()

Solution (Python):
import sys

N = int(sys.stdin.readline().rstrip())

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

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

for i in range(1, 10001):
    if 1000*i >= N:
        print(1000*i-N)
        break

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

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

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

    for i in range(15):
        n -= 1000
        if n < 0:
            return -n
        elif n == 0:
            return n
    


print(solve())

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

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

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

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

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

print(ans)

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

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 if n%1000!=0 else 0)

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

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

Solution (Python):
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case 


if __name__ == "__main__":
    n = int_in()
    n %= 1000
    n = n if n == 0 else 1000 - n
    out(n)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

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

Solution (Python):
N,=map(int, input().split()) 
for i in range(10000):
  if i*1000>=N:
    print(i*1000-N)
    exit()

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

amari = N % 1000

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

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

c = 0
for i in range(1000,11000, 1000):
    if i >= n:
        c = i - n
        break
print(c)

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

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

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

for i in range(1,15):
    x = 1000*i - n
    if(0 <= x and x < 1000):
        print(x)
        exit()

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

print((1000 - (n % 1000)) % 1000)

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

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

Solution (Python):

if __name__ == "__main__":
    N = int(input())
    payment = 0
    while N-payment > 0:
        payment += 1000
    print(payment-N)

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

while N > 0:
    N -= 1000
print(-N)

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

q, mod = divmod(N, 1000)

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

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

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

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

Solution (Python):
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

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

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

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

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

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

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

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

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

def li():
    return [int(x) for x in input().split()]

N = int(input())

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

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

print(math.ceil(N/1000)*1000 - N)

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

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]


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

    
if __name__ == "__main__":
    main()

Solution (Python):

import sys


def solve(N: int):
    x = N // 1000
    N -= x * 1000
    if N == 0:
        print(0)
    else:
        print(1000 - N)
    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())
if N%1000 == 0:
  print(0)
  exit()

print(1000-N%1000)

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

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

Solution (Python):
import math

n = int(input())

print(math.ceil(n/1000)*1000-n)

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

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

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

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

c = math.ceil(a / 1000)

print(c * 1000 - a)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

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

    price = 0
    while True:
        if n <= price:
            break
        price += 1000

    print(price - n)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

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

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(0)
else:
    print(1000-a)

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

Solution (Python):
A=int(input())
A -= 1000*(A//1000)
if A!=0:
    print(1000-A)
else:
    print(0)

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

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

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







money = 0
while True:
    if money >= a:
        print(money-a)
        break
    else :
        money += 1000

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

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

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

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

Solution (Python):
N = int(input())
ans = 1000 - N%1000
if ans == 1000:
    ans=0
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):
import math


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

Solution (Python):
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    print(0 if n % 1000 == 0 else 1000 - n % 1000)


if __name__ == '__main__':
    main()