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.



Sample input:
1900


Sample output:
100

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
INF = 10**18


if __name__ == "__main__":
    n = int(input())
    a = 1000
    while True:
        if a >= n:
            break
        a+=1000
    print(a-n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import  math
li = int(input())
x = math.ceil(li / 1000)

print(x * 1000 - li)

Submission status: Accepted

Solution code:
a =  input()
a = int(a)
b = a
cnt = 0
while True:
    b -= 1000
    cnt +=1
    if b <= 0:
        break
print(cnt*1000 - a)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    remainder = N % 1000
    quotient = int(N / 1000)
    ans = 0
    if N < 1000:
        ans = 1000 - N
    elif remainder == 0:
        ans = 0
    elif remainder > 0:
        ans = 1000 - remainder

    print(f'{ans}')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

n=1
kane=1000*n

while True:
    if N<=kane:
        print(kane-N)
        break
    else:
        n+=1
        kane=1000*n

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

    print((10000-n)%1000)


def b():
    print('')



def c():
    print('')



def d():
    print('')


a()

Submission status: Accepted

Solution code:
N = int(input())
sen = 1000
q = N // sen
if N > q * sen:
    print(abs(N - ((q + 1) * sen)))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input()) % 1000

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = int(n / 1000)
    b = int(n % 1000)
    if b == 0:
        print(0)
        return
    a += 1
    print((a * 1000) - n)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python

if __name__ == "__main__":
    a = input()
    a = int(a)
    if a%1000 == 0:
        print(0)
    else:
        print(1000-a%1000)

Submission status: Accepted

Solution code:
n = int(input())
if n % 1000 == 0:
  print("0")
  exit()
print(1000 - (n % 1000))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ans = 1000-n%1000
    if ans == 1000:
        print(0)
    else:
        print(ans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 0

for i in range(11):
  if i*1000 - n < 1000:
    ans = i*1000 - n
    
  elif i*1000 - n > 1000:
    i += 1
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
yen = 1000

if N % 1000 == 0:
    ans = 0
else:
    while N > 0:
        N = N - yen
    ans = abs(N)

print(ans)

Submission status: Accepted

Solution code:
N= int(input())

ans =  (1000 - N%1000) %1000

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input()

if int(a) % 1000 == 0:
  print("0")
else:
  print(str(1000 - int(a) % 1000))

Submission status: Accepted

Solution code:
N = int(input())

C = N // 1000
T = N - C * 1000
ans = 1000 - T
if ans >= 1000:
    ans = 1000 - ans
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
if n >= 1000:
    s = 1000
    i = 1000
    while n > s:
        s += i
    # print(s)
    print(s-n)
else:
    print(1000-n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

ans = N%1000
if ans!=0:
    ans = 1000-N%1000

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
 
s = int(s)

s = s % 1000

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n=int(input())
if(n%1000==0):
  print("0")
else:
  k=math.ceil(n/1000)
  print((k*1000)-n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())


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

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    print(math.ceil(n/1000)*1000 - n)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""Untitled45.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1chuGB-wcuZOks_CainjNbE3q0Mhq_H-D
"""

n = int(input())
if n <= 1000:
  print(int(1000-n))
elif n <= 2000:
  print(int(2000-n))
elif n <= 3000:
  print(int(3000-n))
elif n <= 4000:
  print(4000-n)
elif n <= 5000:
  print(int(5000-n))
elif n <= 6000:
  print(int(6000-n))
elif n <= 7000:
  print(int(7000-n))
elif n <= 8000:
  print(int(8000-n))
elif n <= 9000:
  print(int(9000-n))
elif n <= 10000:
  print(int(10000-n))

Submission status: Accepted

Solution code:
N = int(input())
ans = N % 1000

if ans != 0:
  ans = 1000 - ans

print(ans)

Submission status: Accepted

Solution code:
x=int(input())
res = 1000-x%1000
if x%1000==0:
    res = 0
print(res)

Submission status: Accepted

Solution code:
n = int(input())

while n > 1000:
    n -= 1000

print(1000 - n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
N = input()


ans = int(N[-3:])

ans = 1000 - ans

if ans == 1000:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

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

Submission status: Accepted

Solution code:
from collections import *

# def solve():


# for _ in range(int(input())):
#     solve()
n = int(input())
if n%1000 == 0:
    print(0)
else:
    print(1000 - n%1000)

Submission status: Accepted

Solution code:
N = int(input())
if N<=1000:
    print(1000-N)
elif N<=2000:
    print(2000-N)
elif N<=3000:
    print(3000-N)
elif N<=4000:
    print(4000-N)
elif N<=5000:
    print(5000-N)
elif N<=6000:
    print(6000-N)
elif N<=7000:
    print(7000-N)
elif N<=8000:
    print(8000-N)
elif N<=9000:
    print(9000-N)
elif N<=10000:
    print(10000-N)

Submission status: Accepted

Solution code:
n = int(input())
print(((n - 1) // 1000 + 1) * 1000 - n)
# for ttt in range(int(input())):
# 	#n = int(input())
# 	#l = list(map(int, input().split()))
# 	# a, b, n = map(int, input().split())
# 	# x = 0
# 	# if a > b:
# 	# 	a, b = b, a
# 	# while b <= n:
# 	# 	a, b = b, a + b
# 	# 	x += 1
# 	# print(x)
# 	s = input()
# 	if len(s) <= 10:
# 		print(s)
# 	else:
# 		print(s[0] + str(len(s) - 2) + s[-1])

Submission status: Accepted

Solution code:
N=int(input())
quotient=N//1000
for i in range(quotient+1):
    N=N-1000
    if N<=0:
        break
print(abs(N))

Submission status: Accepted

Solution code:
N = input()

N_int = int(N)

# 頭悪いやり方
if N_int <= 1000:
    print(1000 - N_int)
elif N_int <= 2000:
    print(2000 - N_int)
elif N_int <= 3000:
    print(3000 - N_int)
elif N_int <= 4000:
    print(4000 - N_int)
elif N_int <= 5000:
    print(5000 - N_int)
elif N_int <= 6000:
    print(6000 - N_int)
elif N_int <= 7000:
    print(7000 - N_int)
elif N_int <= 8000:
    print(8000 - N_int)
elif N_int <= 9000:
    print(9000 - N_int)
elif N_int <= 10000:
    print(10000 - N_int)
else: # 適当
    print(500)

Submission status: Accepted

Solution code:
N = int(input())
if N % 1000 == 0:
    print(0)
elif N < 1000:
    i = 1000
    print(i-N)
elif N < 2000:
    i = 2000
    print(i-N)
elif N < 3000:
    i = 3000
    print(i-N)
elif N < 4000:
    i = 4000
    print(i-N)
elif N < 5000:
    i = 5000
    print(i-N)
elif N < 6000:
    i = 6000
    print(i-N)
elif N < 7000:
    i = 7000
    print(i-N)
elif N < 8000:
    i = 8000
    print(i-N)
elif N < 9000:
    i = 9000
    print(i-N)
elif N < 10000:
    i = 10000
    print(i-N)

Submission status: Accepted

Solution code:
n = input()
s=1000
f=0
if(int(n)<s):
    print(s-int(n))
else:
    if(int(n)%s==0):
        print(0)
    else:
        print(s*(int(n[0])+1)-int(n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline

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

Submission status: Accepted

Solution code:
import sys
readline=sys.stdin.readline

N=int(readline())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

a = N %1000

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

i = int(input())
j = math.ceil(i / 1000)
okane = j * 1000 

print(okane - i)

Submission status: Accepted

Solution code:
import  math
N=int(input())
A=N/1000
B=math.ceil(A)
if A==0:
    print(0)
else:
    print(B*1000-N)

Submission status: Accepted

Solution code:
import sys
#DEBUG = True
DEBUG = False
if DEBUG:
    f=open("202007_1st/A_input.txt")
else:
    f=sys.stdin
N=int(f.readline().strip())
R=N%1000
if R==0:
    print(R)
else:
    print(1000-(N%1000))
f.close()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
payment = abs(n - math.ceil(n / 1000) * 1000)
print(payment)

Submission status: Accepted

Solution code:
n = int(input())

if n < 1000:
    print(1000 - n)
else:
    for i in range(1,n):
        if 1000*i >= n:
            print(1000*i - n)
            break

Submission status: Accepted

Solution code:
x = int(input())

a = x % 1000

if a == 0:
  print("0")
  exit()

print(1000 - a)

Submission status: Accepted

Solution code:
N = int(input())
r = N % 1000
if r > 0:
    print(1000 - (N % 1000))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

if N==10000:
    print(0)
elif N>9000:
    print(10000-N)
elif N>8000:
    print(9000-N)
elif N>7000:
    print(8000-N)
elif N>6000:
    print(7000-N)
elif N>5000:
    print(6000-N)
elif N>4000:
    print(5000-N)
elif N>3000:
    print(4000-N)
elif N>2000:
    print(3000-N)
elif N>1000:
    print(2000-N)
else:
    print(1000-N)

Submission status: Accepted

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=1):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.node_size=len(ls)+1
                self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.node_size=int(input())
        else:
            self.node_size=inp_size
        self.edges,_=GI(self.node_size,self.node_size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.node_size=len(ls)+1
        self.edges,_=GI(self.node_size,self.node_size-1,ls,index=index)
        return
 
    def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        while q:
            c=q.popleft()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def parent(self,x):
        return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1)
 
    def topological_sort(self,x):  # return topological sort of the tree
        tps=[]
        q=deque([x])
        v=[None]*self.node_size
        v[x]=0
        while q:
            c=q.popleft()
            tps.append(c)
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=0
        return tps
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.node_size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.node_size
        self.ETout=[-1]*self.node_size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def doubling_LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.depth=[None]*self.node_size
            self.depth=self.bfs(0,func=lambda pr,prv,nxt,dist:prv+1)
            self.par=self.bfs(0,func=lambda pr,prv,nxt,dist:pr)
            self.db=[self.par]
            for i in range(self.node_size.bit_length()):
                #show(self.db)
                self.db+=[[self.db[-1][self.db[-1][i]] for i in range(self.node_size)]]
            self.LCA_init_stat=True
        dx=self.depth[x]
        dy=self.depth[y]
        if dx>dy:
            dx,dy=dy,dx
        c=self.node_size.bit_length()
        while c>0:
            if dx+c<=dy:
                x=self.db[c][x]
                dx+=1<<c
            c>>=1
        
        if x==y:
            return x
        
        c=self.node_size.bit_length()
        while c>0:
            if self.db[c][x]!=self.db[c][y]:
                x=self.db[c][x]
                y=self.db[c][y]
            c>>=1
        
        return self.par[x]
        
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.node_size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
    def __str__(self):
        return  str(self.edges)
 
    def show(self):
        if all([all([d==1 for nd,d in e]) for e in self.edges]):
            print( [[nd for nd,d in e] for e in self.edges] )
        else:
            print(self)
 
    def dfs2(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.node_size
        v[x]=root_v
        dfs_tr=[x]
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
                    dfs_tr+=nb,
        return v,dfs_tr

class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos

    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)

show_flg=False
show_flg=True

ans=0

#h,w,K=LI()
n=I()
k=((n+999)//1000)*1000
ans=((n+999)//1000)*1000-n

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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


# for i in range(1, 10+1):
#     have = 1000 * i

#     if 0 <= have - N < 1000:
#         print(have - N)
#         exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input()) #10000以下

for i in range(11):
  if n >= 1000:
    n -= 1000
    
  if n < 1000 and n != 0:
    print(1000 - n)
    break

  if n == 0:
    print(n)
    break

Submission status: Accepted

Solution code:
N = input()

if int(N[-3:]) == 0:
    print(0)
else:
    print(1000 - int(N[-3:]))

Submission status: Accepted

Solution code:
N = int(input())
if 1 <= N <= 999:
  print(1000-N)
elif int(str(N)[1:]) ==0:
  print(0)
else:
    print(1000-int(str(N)[1:]))

Submission status: Accepted

Solution code:
import math
N=int(input())
ans=0
while (ans-N<0):
  ans+=1000

print(ans-N)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n =int(input())
if n%1000==0:
  print(0)
else:
  print(1000-(n%1000))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
if n < 1000:
    print(1000 - n)
else:
    n = str(n)
    firt = n[0]
    firt = int(firt)
    firt = str(firt)
    length = len(n) - 1
    leng = "0" * length
    fill = firt + leng
    fill = int(fill)
    res = int(n) - fill
    if res == 0: print(res)
    else:
        print(1000 - res)

Submission status: Accepted

Solution code:
N = int(input())
pay = 0
while N > pay:
  pay += 1000
print(pay-N)

Submission status: Accepted

Solution code:
a = int(input())
print(1000*bool(a%1000)-a%1000)

Submission status: Accepted

Solution code:
import math
import sys

def main():

    input = sys.stdin.buffer.readline
    n = int(input())
    if(n%1000 == 0):
        print(0)
    else:
        a = n // 1000
        print((a+1)*1000-n)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())

if a <1000:
    print(1000-a)
    exit()

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

B = int(a//1000+1)*1000
C = B-a
print(C)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
k = 10000
ans = (k - N) % 1000
print(ans)

Submission status: Accepted

Solution code:
N = str(input())

if len(N) <4:
    print(1000-int(N))
elif len(N) == 5:
    print(10000-int(N))
else:
    n = (1+int(N[0]))*1000 
    if int(N) % 1000 == 0:
      print(0)
    else:
      print(n - int(N))

Submission status: Accepted

Solution code:
import math
N = int(input())
s = N/1000
a = math.ceil(s)*1000
b = a-N
print(b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
M = round(N+500, -3)
if M-N == 1000:
  print(0)
else:
  print(M-N)

Submission status: Accepted

Solution code:
N = int(input())
X = int(0)

if N == 10000:
    print(0)
elif N < 1000:
    X = 1000 - N
    print(X)
else:
    for i in range(11) :
        if N < i * 1000:
            X = i * 1000 - N
            if X == 1000:
                print(0)
            else:
                print(X)
            break

Submission status: Accepted

Solution code:
x = int(input())
while x > 0:
    x -= 1000
print(abs(x))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N=int(input())
print((1000-N%1000)%1000)

Submission status: Accepted

Solution code:

a = int(input())
b = 0
while b < a:
    b = b + 1000

print(abs(a-b))

Submission status: Accepted

Solution code:
n = int(input())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
for i in range(0,1000000,1000):
    if N <= i:
        print(i-N)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
if n%1000==0:
    print("0")
elif n%1000!=0:
    c=n%1000
    print(1000-c)

Submission status: Accepted

Solution code:
N = int(input())

if 0 <= N <= 1000:
    print(1000-N)
elif 1000 < N <= 2000:
    print(2000-N)
elif 2000 < N <= 3000:
    print(3000-N)
elif 3000 < N <= 4000:
    print(4000-N)
elif 4000 < N <= 5000:
    print(5000-N)
elif 5000 < N <= 6000:
    print(6000-N)
elif 6000 < N <= 7000:
    print(7000-N)
elif 7000 < N <= 8000:
    print(8000-N)
elif 8000 < N <= 9000:
    print(9000-N)
else:
    print(10000-N)