CodeEff/ECCO huggingface dataset:
# Original solution
class BIT():
    def __init__(self,size):
        self.size=size
        self.node=[0]*(size+1)

    def sum(self,idx):
        ret=0
        while idx>0:
            ret+=self.node[idx]
            idx-=idx&(-idx)
        return ret

    def add(self,idx,x):
        while idx<=self.size:
            self.node[idx]+=x
            idx+=idx&(-idx)

n,k=list(map(int,input().split()))
a=[int(input()) for _ in range(n)]
diff=[]
for i in range(n):
    diff.append(a[i]-k)
for i in range(n-1):
    diff[i+1]+=diff[i]
bit=BIT(n)
s=set([])
for i in range(n):
    bit.add(i+1,1)
    s.add(diff[i])
li=list(s)
li.sort()
d={}
for i in range(len(li)):
    d[li[i]]=i
pos=[[] for _ in range(len(li))]
for i in range(n):
    idx=d[diff[i]]
    pos[idx].append(i+1)
ans=0
for i in range(len(li)):
    for j in pos[i]:
        ans+=bit.sum(n)-bit.sum(j)
        if diff[j-1]>=0:
            ans+=1
        bit.add(j,-1)
print(ans)


# Optimized solution
class BIT():
    def __init__(self,size):
        self.size=size
        self.node=[0]*(size+1)

    def sum(self,idx):
        ret=0
        while idx>0:
            ret+=self.node[idx]
            idx-=idx&(-idx)
        return ret

    def add(self,idx,x):
        while idx<=self.size:
            self.node[idx]+=x
            idx+=idx&(-idx)

n,k=list(map(int,input().split()))
a=[int(input()) for _ in range(n)]
diff=[]
for i in range(n):
    diff.append(a[i]-k)
for i in range(n-1):
    diff[i+1]+=diff[i]
bit=BIT(n)
s=set([])
for i in range(n):
    s.add(diff[i])
li=list(s)
li.sort()
d={}
for i in range(len(li)):
    d[li[i]]=i+1
ans=0
for i in range(n):
    pos=d[diff[i]]
    ans+=bit.sum(pos)
    if diff[i]>=0:
        ans+=1
    bit.add(pos,1)
print(ans)
# Original solution
import sys
from itertools import accumulate

def solve():
    n, k = list(map(int, sys.stdin.readline().split()))
    a = [int(sys.stdin.readline().rstrip()) - k for i in range(n)]
    s = [0] + list(accumulate(a))

    # 座標圧縮
    s = [(si, i) for (i, si) in enumerate(s)]
    s.sort()

    z = [None] * (n + 1)

    num = -1
    p = -float('inf')

    for i in range(n + 1):
        if s[i][0] > p:
            num += 1

        z[s[i][1]] = num
        p = s[i][0]

    # FenwickTreeで転倒数を数える
    ft = FenwickTree(num + 1)

    ans = 0

    for zi in z:
        ans += ft.psum(zi + 1)
        ft.add(zi, 1)

    print(ans)

class FenwickTree:
    def __init__(self, n):
        self.n = n
        self.b = [0] * (n + 1)

    def add(self, i, x):
        i += 1

        while i <= self.n:
            self.b[i] += x
            i += i & (-i)

    def psum(self, r):
        res = 0

        while r > 0:
            res += self.b[r]
            r -= r & (-r)

        return res

if __name__ == '__main__':
    solve()

# Optimized solution
import sys
from itertools import accumulate

inf = 1<<60
ans = 0

def solve():
    n, k = list(map(int, sys.stdin.readline().split()))
    a = [int(sys.stdin.readline().rstrip()) - k for i in range(n)]
    s = [0] + list(accumulate(a))

    MergeSort(s)

    print(ans)

def MergeSort(a):
    if len(a) == 1:
        return a

    apre = MergeSort(a[:len(a)//2])
    asuf = MergeSort(a[len(a)//2:])

    res = merge(apre, asuf)

    return res

def merge(a, b):
    global ans
    na = len(a)
    nb = len(b)

    a.append(-inf)
    b.append(-inf)

    la = 0
    lb = 0

    res = []

    for i in range(na + nb):
        if a[la] <= b[lb]:
            ans += na - la
            res.append(b[lb])
            lb += 1
        else:
            res.append(a[la])
            la += 1

    return res

if __name__ == '__main__':
    solve()
# Original solution
from bisect import bisect_right
import sys
input = sys.stdin.buffer.readline

class BIT:
    def __init__(self, size, values):
        self.size = size
        self.tree = [0] * (size + 1)

        self.values = values
        self.values.sort()
        self.vToI = {v: i for i, v in enumerate(self.values, start=1)}

    def lowerValueIndex(self, v):
        return self.vToI[self.values[bisect_right(self.values, v) - 1]]

    def add(self, index):
        index = self.vToI[index]
        while index <= self.size:
            self.tree[index] += 1
            index += index & (-index)

    def sum(self, index):
        index = self.lowerValueIndex(index)
        ret = 0
        while index:
            ret += self.tree[index]
            index -= index & (-index)
        return ret

    def search(self, value):
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.tree[i + step] < value:
                i += step
                s += self.tree[i]
            step //= 2
        return i + 1

N, K = list(map(int, input().split()))
A = [int(eval(input())) - K for _ in range(N)]

accA = [0] * (N + 1)
for i, a in enumerate(A, start=1):
    accA[i] = accA[i - 1] + a

values = accA + [10**18]
values += [-v for v in values]
values = list(set(values))
tree = BIT(len(values), values)

ans = 0
for i, a in enumerate(accA):
    ans += i - tree.sum(-a - 1)
    tree.add(-a)
print(ans)


# Optimized solution
from bisect import bisect_right
import sys
input = sys.stdin.buffer.readline

class BIT:
    def __init__(self, size):
        self.size = size
        self.tree = [0] * (size + 1)

    def add(self, index):
        while index <= self.size:
            self.tree[index] += 1
            index += index & (-index)

    def sum(self, index):
        ret = 0
        while index:
            ret += self.tree[index]
            index -= index & (-index)
        return ret

    def search(self, value):
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i + step <= self.size and s + self.tree[i + step] < value:
                i += step
                s += self.tree[i]
            step //= 2
        return i + 1

N, K = list(map(int, input().split()))
A = [int(eval(input())) - K for _ in range(N)]

accA = [0] * (N + 1)
for i, a in enumerate(A, start=1):
    accA[i] = accA[i - 1] + a

sToI = {s: i for i, s in enumerate(sorted(list(set(accA))))}
tree = BIT(len(sToI))

ans = 0
for a in [sToI[a] + 1 for a in accA]:
    ans += tree.sum(a)
    tree.add(a)
print(ans)
# Original solution
from itertools import accumulate as acc
class BIT:
  def __init__(self, n):
    self.N = n+1
    self.bit = [0]*self.N
  
  def bit_sum(self, i):
    s = 0
    i += 1
    while i>0:
      s += self.bit[i]
      i -= i & -i
    return s

  def bit_add(self, i, n):
    i += 1
    while i<self.N:
      self.bit[i] += n
      i += i & -i

N, K, *A = list(map(int, open(0).read().split()))
A = [a-K for a in A]
B = [(b,i) for i, b in enumerate(acc(A))]
bit_B = BIT(N)
B.sort(reverse=True)
ans = sum(c[0]>=0 for c in B)
for b,i in B:
  bit_B.bit_add(i,1)
  ans += bit_B.bit_sum(N-1)-bit_B.bit_sum(i)
print(ans)

# Optimized solution
from itertools import accumulate as acc

def bit_sum(ls, i):
  s = 0
  i += 1
  while i>0:
    s += ls[i]
    i -= i & -i
  return s

def bit_add(ls, i, n):
  i += 1
  while i<len(ls):
    ls[i] += n
    i += i & -i

N, K, *A = list(map(int, open(0).read().split()))
A = [a-K for a in A]
B = [(b,i) for i, b in enumerate(acc(A))]
bit_B = [0]*(N+1)
B.sort(reverse=True)
ans = sum(c[0]>=0 for c in B)
for b,i in B:
  bit_add(bit_B,i,1)
  ans += bit_sum(bit_B,N-1)-bit_sum(bit_B,i)
print(ans)
# Original solution
from itertools import accumulate

def main():
    class BIT:
        def __init__(self, N):
            self.size = N
            self.tree = [0] * (N + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

    N, K, *A = list(map(int, open(0).read().split()))

    B = [0] + list(accumulate(a - K for a in A))

    memo = {n: i for i, n in enumerate(sorted(set(B)), 1)}
    bit = BIT(N + 1)

    ans = 0
    for b in map(memo.get, B):
        ans += bit.sum(b)
        bit.add(b, 1)

    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
from itertools import accumulate

def main():
    N, K, *A = list(map(int, open(0).read().split()))

    B = [0] + list(accumulate(a - K for a in A))

    memo = {n: i for i, n in enumerate(sorted(set(B)), 1)}

    N += 1
    tree = [0] * (N + 1)

    def bit_sum(i):
        s = 0
        while i > 0:
            s += tree[i]
            i -= i & -i
        return s

    def bit_add(i, x):
        while i <= N:
            tree[i] += x
            i += i & -i

    ans = 0
    for b in map(memo.get, B):
        ans += bit_sum(b)
        bit_add(b, 1)

    print(ans)

if __name__ == '__main__':
    main()
# Original solution
import sys
from copy import deepcopy

F = sys.stdin
N, K = list(map(int, F.readline().strip("\n").split()))
A = [None] * (N + 1)
A[0] = 0
A_order = {0}
for a in range(N):
    A[a+1] = int(F.readline().strip("\n")) - K + A[a]
    A_order |= {A[a+1]}
maxA = len(A_order)
A_order = list(A_order)
A_order.sort()

compressed_A = dict()
for i in range(maxA):
    compressed_A[A_order[i]] = i

bit = [0] * (maxA + 1)
total_inversion = 0
for a in A:
    b = compressed_A[a] + 1
    while b <= maxA + 1: 
        bit[b - 1] += 1
        b += b & -b

    #total sum
    upper = maxA + 1
    upper_sum = 0
    while upper > 0:
        upper_sum += bit[upper - 1]
        upper -= upper & -upper

    #lower sum
    lower = compressed_A[a] + 1
    lower_sum = 0
    while lower > 0:
        lower_sum += bit[lower - 1]
        lower -= lower & -lower

    total_inversion += upper_sum - lower_sum
 
print((N * (N + 1) // 2 - total_inversion))

# Optimized solution
import sys
from copy import deepcopy

F = sys.stdin
N, K = list(map(int, F.readline().strip("\n").split()))
A = [None] * (N + 1)
A[0] = 0
A_order = {0}
for a in range(N):
    A[a+1] = int(F.readline().strip("\n")) - K + A[a]
    A_order |= {A[a+1]}
maxA = len(A_order)
A_order = list(A_order)
A_order.sort()

compressed_A = dict()
for i in range(maxA):
    compressed_A[A_order[i]] = i

bit = [0] * (maxA + 1)
total_inversion = 0
for i in range(N+1):
    b = compressed_A[A[i]] + 1
    while b <= maxA + 1: 
        bit[b - 1] += 1
        b += b & -b

    #lower sum
    lower = compressed_A[A[i]] + 1
    lower_sum = 0
    while lower > 0:
        lower_sum += bit[lower - 1]
        lower -= lower & -lower

    total_inversion += i + 1 - lower_sum
 
print((N * (N + 1) // 2 - total_inversion))
# Original solution
from bisect import bisect_right as br
n,k=list(map(int,input().split()))
b=[0]*(n+1)
def f(x):
    c=0
    while x>0:
        c+=b[x]
        x-=x&-x
    return c
def g(x,a):
    while x<n+1:
        b[x]+=a
        x+=x&-x
for i in range(n):
    g(i+1,int(eval(input()))-k)
c=[0]
d=0
for i in range(1,n+1):
    t=f(i)
    k=br(c,t)
    c.insert(k,f(i))
    d+=i-k
print(((n*(n+1))//2-d))

# Optimized solution
n,k=list(map(int,input().split()))
b=[0]*(n+1)
for i in range(n):
    b[i+1]=b[i]+int(eval(input()))-k
a=sorted(set(b))
s={a[i-1]:i for i in range(1,len(a)+1)}
c=[]
for i in b:
    c.append(s[i])
b=[0]*(len(a)+1)
def f(x):
    c=0
    while x>0:
        c+=b[x]
        x-=x&-x
    return c
def g(x):
    while x<len(a)+1:
        b[x]+=1
        x+=x&-x
e=0
for i in range(n+1):
    e+=f(c[i])
    g(c[i])
print(e)
# Original solution
class BIT:
    def __init__(self,n):
        self.size=n
        self.tree=[0]*-~n
    def sum(self,i):
        s=0
        while i:
            s+=self.tree[i]
            i-=i&-i
        return s
    def add(self,i,x):
        while i<=self.size:
            self.tree[i]+=x
            i+=i&-i
n,k,*a=list(map(int,open(0).read().split()))
a=[t-k for t in a]
for i in range(1,n):
    a[i]+=a[i-1]
d={}
for i,v in enumerate(sorted(set(a+[0])),1):
    d[v]=i
for i in range(n):
    a[i]=d[a[i]]
b=BIT(max(a))
b.add(d[0],1)
c=0
for i,p in enumerate(a):
    c+=b.sum(p)
    b.add(p,1)
print(c)

# Optimized solution
class BIT:
    def __init__(self,n):
        self.size=n
        self.tree=[0]*-~n
    def sum(self,i):
        s=0
        while i:
            s+=self.tree[i]
            i-=i&-i
        return s
    def add(self,i,x):
        while i<=self.size:
            self.tree[i]+=x
            i+=i&-i
n,k,*a=list(map(int,open(0).read().split()))
a=[t-k for t in a]
for i in range(1,n):
    a[i]+=a[i-1]
d={}
for i,v in enumerate(sorted(set(a+[0])),1):
    d[v]=i
for i in range(n):
    a[i]=d[a[i]]
b=BIT(max(a))
b.add(d[0],1)
c=0
for p in a:
    c+=b.sum(p)
    b.add(p,1)
print(c)
# Original solution
from bisect import bisect,insort
n,k = (int(i) for i in input().split())
a = [int(eval(input()))-k for i in range(n)]
b = [[0,0]]
for i in range(n): b.append([-(a[i]-b[-1][0]),-(i+1)])
b.sort()
q,ans,num = [-b[0][1]],0,1
for i,j in b[1:]:
	c = bisect(q,-j)
	ans+=num-c
	num+=1
	insort(q,-j,c,c)
print(ans)

# Optimized solution
n,k = (int(i) for i in input().split())
a = [int(eval(input()))-k for i in range(n)]
b = [[0,0]]
for i in range(n): b.append([b[-1][0]+a[i],i+1])
b.sort()
num,c = 1,[[b[0][1],1]]
for i in range(1,n+1):
	if b[i][0]!=b[i-1][0]: num+=1
	c.append([b[i][1],num])
c,d,ans = sorted(c),[0]*(n+2),0
def add(i):
	while i<=n+1:
		d[i] += 1
		i += i & -i
def get(i):
	s = 0
	while i:
		s += d[i]
		i -= i & -i
	return s
for i,j in c:
	ans+=get(j)
	add(j)
print(ans)
# Original solution
import bisect

N,K = list(map(int,input().split()))
src = [int(eval(input())) for i in range(N)]
if N == 1:
    print((int(src[0]>=K)))
    exit()

cums = [0]
for a in src:
    cums.append(cums[-1] + a - K)

s_cums = sorted(cums)
cmp = []
for a in cums:
    i = bisect.bisect(s_cums, a)
    cmp.append(i-1)

bit = [0] * (N+1)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = 0
for a in cmp:
    ans += bit_sum(a)
    bit_add(a, 1)
print(ans)


# Optimized solution
N,K = list(map(int,input().split()))
src = [int(eval(input())) for i in range(N)]

cums = [(0,1)]
for i,a in enumerate(src):
    cums.append((cums[-1][0] + a - K, i+2))

bit = [0] * (N+2)
def bit_add(a,w):
    x = a
    while x <= N:
        bit[x] += w
        x += (x & -x)

def bit_sum(a):
    x = a
    ret = 0
    while x > 0:
        ret += bit[x]
        x -= (x & -x)
    return ret

ans = 0
for i,a in sorted(cums):
    ans += bit_sum(a-1)
    bit_add(a, 1)
print(ans)
# Original solution
N, K = list(map(int, input().split()))
a = []
for _ in range(N):
    a.append(int(eval(input()))-K)

ans = 0
for i in range(N):
    for j in range(i+1, N+1):
#         print(a[i:j])
        if sum(a[i:j]) >= 0:
            ans += 1
            
print(ans)

# Optimized solution
N, K = list(map(int, input().split()))
a = []
for _ in range(N):
    a.append(int(eval(input()))-K)
    
su = 0
v = [(0, 0)]
for i in range(N):
    su += a[i]
    v.append((su, i+1))
v = sorted(v)

data = [0]*(N+5)

def sumation(i):
    s = 0
    while i > 0:
        s += data[i]
        i -= i & -i
    return s
    
def add(i, x):
    while i <= N+2:
        data[i] += x
        i += i & -i
ans = 0
for e, i in v:
    ans += sumation(i+1)
    add(i+1, 1)
    
print(ans)
# Original solution
from bisect import bisect_left
class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]+=x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]+self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1+c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)
N,K=list(map(int,input().split()))
a=[int(eval(input())) for i in range(N)]
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]+a[i]
B=[cum[i]-i*K for i in range(N+1)]

dic={}
li=sorted(B)
for i in range(N+1):
    dic[B[i]]=bisect_left(li,B[i])
seg=SEGTree(N+1)
ans=0
for i in range(N+1):
    ans+=seg.get(0,dic[B[i]]+1)
    seg.update(dic[B[i]],1)
print(ans)


# Optimized solution
from bisect import bisect_left
class BIT:
    def __init__(self,N):
        self.N=N
        self.bit=[0]*N
    def add(self,a,w):
        x=a
        while(x<self.N):
            self.bit[x]+=w
            x|=x+1
    def get(self,a):
        ret,x=0,a-1
        while(x>=0):
            ret+=self.bit[x]
            x=(x&(x+1))-1
        return ret
    def cum(self,l,r):
        return self.get(r)-self.get(l)

N,K=list(map(int,input().split()))
a=[int(eval(input())) for i in range(N)]
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]+a[i]
B=[cum[i]-i*K for i in range(N+1)]

dic={}
li=sorted(B)
for i in range(N+1):
    dic[B[i]]=bisect_left(li,B[i])
bit=BIT(N+1)
ans=0
for i in range(N+1):
    ans+=bit.get(dic[B[i]]+1)
    bit.add(dic[B[i]],1)
print(ans)
# Original solution
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return list(map(int,input().split()))
def lmp(): return list(map(int,input().split()))

n=int(eval(input()))
print((((-1)*n)%1000))

# Optimized solution
n=int(eval(input()))
print(((-n)%1000))
# Original solution
import math
n = int(eval(input()))
if n % 1000 == 0:
  print((0))
else:
  print((math.ceil(n / 1000) * 1000 - n))

# Optimized solution
print((-int(eval(input()))%1000))
# Original solution
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

# Optimized solution
N = int(eval(input()))
print(((1000 - N % 1000) % 1000))
# Original solution
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

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

if __name__ == "__main__":
    main()


# Optimized solution
print(((1000-int(eval(input()))%1000)%1000))
# Original solution
N = int(eval(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))

# Optimized solution
n = int(eval(input()))
if n % 1000 == 0:    
    ans = 0
else:    
    ans = 1000- n % 1000

print(ans)
# Original solution
N = int(eval(input()))
if N % 1000 == 0:
  print((0))
else:
  print((1000 - (N % 1000)))

# Optimized solution
n = int(eval(input()))
if n % 1000 == 0:
  print((0))
else:
  print((1000 - n % 1000))
# Original solution
n = int(eval(input()))
r = n % 1000
x = 0 if r == 0 else 1000-r
print(x)

# Optimized solution
print((-int(eval(input()))%1000))
# Original solution
n = int(eval(input()))
print(((10000-n) % 1000))

# Optimized solution
S = int(eval(input()))
if S % 1000 == 0:
    W = 0
else:
    W = 1000-(S % 1000)
print(W)
190
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()

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

# Optimized solution
import sys

def I(): return int(sys.stdin.readline().rstrip())

N = I()

print((999-(N-1)%1000))
# Original solution
n=int(eval(input()))
print(((10000-n)%1000))

# Optimized solution
n=int(eval(input()))
print(((1000-n%1000)%1000))
# Original solution
def main():
    arg = int(eval(input()))
    if arg % 1000 == 0:
        ans = 0
    else:
        ans = 1000 - (arg % 1000)
    print((str(ans)))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    m = int(eval(input())) % 1000
    ans = 0 if m == 0 else 1000 - m
    print((str(ans)))


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input())) % 1000
if n == 0:
    print((0))
else:
    print((1000 - n))

# Optimized solution
n = int(eval(input()))
print(((1000 - n % 1000) % 1000))
# Original solution
N = int(eval(input()))
ans = (1000 - N % 1000) % 1000
print(ans)

# Optimized solution
N = int(eval(input()))

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

ans = k * 1000 - N
print(ans)
# Original solution
x=int(eval(input()))
from math import ceil
u=ceil(x/1000)*1000
print((u-x))

# Optimized solution
from math import ceil
x=int(eval(input()))

print((ceil(x/1000)*1000-x))
# Original solution
n = int(eval(input()))
i=1
ans=0
for i in range(100):
	if i*1000>=n:
		ans = i*1000-n
		break
print(ans)


# Optimized solution
n=int(eval(input()))
if n%1000==0:
  print((0))
else:print((1000-n%1000))
# Original solution
n = int(eval(input()))
x = (10000-n)%1000
print(x)


# Optimized solution
N = int(eval(input()))

if N % 1000 == 0:
    print((0))
else:
    print((1000-N % 1000))
# Original solution
N = int(eval(input()))
print(((1000-N%1000)%1000))

# Optimized solution
N = int(eval(input()))
tmp = N%1000
if tmp == 0:
    print((0))
else:
    print((1000 - tmp))