Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03240 (python)

Fixed submission:
n=int(input())
import sys
place=[]
place_0=[]
place_all=[]
for i in range(n):
    x,y,h=map(int,input().split())
    place_all.append((x,y,h))
    if h==0:
        place_0.append((x,y,h))
    else:
        place.append((x,y,h))
for x in range(0,101):
    for y in range(0,101):
        if not place==[]:
            H=abs(place[0][0]-x)+abs(place[0][1]-y)+place[0][2]
        else:
            H=1
        for i in range(0,n):
            d=abs(place_all[i][0]-x)+abs(place_all[i][1]-y)
            if place_all[i][2]>0:
                if H==place_all[i][2]+d:
                    count=1
                else:
                    count=0
                    break
            else:
                if d>=H:
                    count=1
                else:
                    count=0
                    break
        if count==1:
            print(x,y,H)
            sys.exit()

Buggy submission (verdict: Runtime Error):
n=int(input())
import sys
place=[]
place_0=[]
for i in range(n):
    x,y,h=map(int,input().split())
    if h==0:
        place_0.append((x,y,h))
    else:
        place.append((x,y,h))
for x in range(0,101):
    for y in range(0,101):
        for i in range(len(place)-1):
            a=abs(place[i][0]-x)+abs(place[i][1]-y)
            b=abs(place[i+1][0]-x)+abs(place[i+1][1]-y)
            if b-a==place[i][2]-place[i+1][2]:
                count=1
            else:
                count=0
                break
        if count==1:
            H=abs(place[0][0]-x)+abs(place[0][1]-y)+place[0][2]
            print(x,y,H)
            sys.exit()

Buggy submission (verdict: Runtime Error):
n=int(input())
import sys
place=[]
place_0=[]
for i in range(n):
    x,y,h=map(int,input().split())
    if h==0:
        place_0.append((x,y,h))
    else:
        place.append((x,y,h))
for x in range(0,101):
    for y in range(0,101):
        for i in range(n-1):
            a=abs(place[i][0]-x)+abs(place[i][1]-y)
            b=abs(place[i+1][0]-x)+abs(place[i+1][1]-y)
            if b-a==place[i][2]-place[i+1][2]:
                count=1
            else:
                count=0
                break
        if count==1:
            H=abs(place[0][0]-x)+abs(place[0][1]-y)+place[0][2]
            print(x,y,H)
            sys.exit()
Problem p03262 (python)

Fixed submission:
n,x=map(int,input().split())
x_list=list(map(int,input().split()))
d_list=[]
for i in x_list:
    d_list.append(abs(x-i))
import fractions
if n==1:
    answer=d_list[0]
else:
    answer=fractions.gcd(d_list[0],d_list[1])
    for i in range(2,n):
        answer=fractions.gcd(answer,d_list[i])
print(answer)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
x_list=list(map(int,input().split()))
d_list=[]
for i in x_list:
    d_list.append(abs(x-i))
import fractions
answer=fractions.gcd(d_list[0],d_list[1])
for i in range(2,n):
    answer=fractions.gcd(answer,d_list[i])
print(answer)
Problem p03450 (python)

Fixed submission:
import sys
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**9
x_list=[INF]*n
stack=[]
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        stack.append(i)
        while len(stack)>0:
            now=stack.pop()
            for j in graph[now]:
                if x_list[j[0]]==INF:
                    x_list[j[0]]=x_list[now]+j[1]
                    stack.append(j[0])
                else:
                    if x_list[j[0]]==x_list[now]+j[1]:
                        pass
                    else:
                        print('No')
                        sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
    l,r,d=map(int,input().split())
    graph[r-1].append((l-1,-d))
    graph[l-1].append((r-1,d))
INF=10**10
x_list=[INF]*n
import sys
def dfs(x):
    for i in graph[x]:
        if x_list[i[0]]==INF:
            x_list[i[0]]=x_list[x]+i[1]
            dfs(i[0])
        else:
            if x_list[i[0]]==x_list[x]+i[1]:
                pass
            else:
                print('No')
                sys.exit()
for i in range(n):
    if x_list[i]==INF:
        x_list[i]=0
        dfs(i)
print('Yes')
Problem p03488 (python)

Fixed submission:
s=input()
x,y=map(int,input().split())
h=[]
v=[]
num=0
m=1
for i in s:
    if i=='F':
        num+=1
    else:
        if num!=0:
            if m==1:
                h.append(num)
            else:
                v.append(num)
        m=-m
        num=0
if num!=0:
    if m==1:
        h.append(num)
    else:
        v.append(num)
if s[0]=='F':
    x=x-h[0]
    del h[0]
sumh=sum(h)
nh=len(h)
dph=[]
if nh!=0:
    for i in range(nh+1):
        sub_list=[False]*(1+2*sumh)
        dph.append(sub_list)
    dph[0][sumh]=True
    for i in range(1,nh+1):
        for j in range(1+2*sumh):
            if j-h[i-1]>=0:
                dph[i][j]=dph[i][j] or dph[i-1][j-h[i-1]]
            if j+h[i-1]<=2*sumh:
                dph[i][j]=dph[i][j] or dph[i-1][j+h[i-1]]
    if 0<=x+sumh<=2*sumh:
        sh=dph[nh][x+sumh]
    else:
        sh=False
else:
    if x==0:
        sh=True
    else:
        sh=False
sumv=sum(v)
nv=len(v)
dpv=[]
if nv!=0:
    for i in range(nv+1):
        sub_list=[False]*(1+2*sumv)
        dpv.append(sub_list)
    dpv[0][sumv]=True
    for i in range(1,nv+1):
        for j in range(1+2*sumv):
            if j-v[i-1]>=0:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j-v[i-1]]
            if j+v[i-1]<=2*sumv:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j+v[i-1]]
    if 0<=y+sumv<=2*sumv:
        sv=dpv[nv][y+sumv]
    else:
        sv=False
else:
    if y==0:
        sv=True
    else:
        sv=False
if sh and sv:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s=input()
x,y=map(int,input().split())
h=[]
v=[]
num=0
m=1
for i in s:
    if i=='F':
        num+=1
    else:
        if num!=0:
            if m==1:
                h.append(num)
            else:
                v.append(num)
        m=-m
        num=0
if num!=0:
    if m==1:
        h.append(num)
    else:
        v.append(num)
if s[0]=='F':
    x=x-h[0]
    del h[0]
sumh=sum(h)
nh=len(h)
dph=[]
if nh!=0:
    for i in range(nh+1):
        sub_list=[False]*(1+2*sumh)
        dph.append(sub_list)
    dph[0][sumh]=True
    for i in range(1,nh+1):
        for j in range(1+2*sumh):
            if j-h[i-1]>=0:
                dph[i][j]=dph[i][j] or dph[i-1][j-h[i-1]]
            if j+h[i-1]<=2*sumh:
                dph[i][j]=dph[i][j] or dph[i-1][j+h[i-1]]
    sh=dph[nh][x+sumh]
else:
    if x==0:
        sh=True
    else:
        sh=False
sumv=sum(v)
nv=len(v)
dpv=[]
if nv!=0:
    for i in range(nv+1):
        sub_list=[False]*(1+2*sumv)
        dpv.append(sub_list)
    dpv[0][sumv]=True
    for i in range(1,nv+1):
        for j in range(1+2*sumv):
            if j-v[i-1]>=0:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j-v[i-1]]
            if j+v[i-1]<=2*sumv:
                dpv[i][j]=dpv[i][j] or dpv[i-1][j+v[i-1]]
    sv=dpv[nv][y+sumv]
else:
    if y==0:
        sv=True
    else:
        sv=False
if sh and sv:
    print('Yes')
else:
    print('No')
Problem p03212 (python)

Fixed submission:
import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)

Buggy submission (verdict: Runtime Error):
import itertools
import math
n = input()

chars = ["3", "5", "7"]
ndigits = int(math.log10(n)) + 1

count = 0
for digit in range(3, ndigits + 1):
    for string in itertools.product(chars, repeat=digit):
        if(string.count("3") == 0):
            continue
        if(string.count("5") == 0):
            continue
        if(string.count("7") == 0):
            continue
        if n >= int("".join(string)):
            count += 1

print(count)
Problem p02554 (python)

Fixed submission:
import sys
import math

mod = 10 ** 9 + 7

N = int(input())

if N <= 1:
    print(0)
    sys.exit()

# ans = comb(N, 2, exact=True) * 2 * (8 ** (N - 2)) + (9 ** N - 8 ** N) * 2
ans = 10 ** N - 8 ** N - (9 ** N - 8 ** N) * 2
print(ans % mod)

Buggy submission (verdict: Runtime Error):
import sys
import math
from scipy.special import comb

mod = 10 ** 9 + 7

N = int(input())

if N <= 1:
    print(0)
    sys.exit()

# ans = comb(N, 2, exact=True) * 2 * (8 ** (N - 2)) + (9 ** N - 8 ** N) * 2
ans = 10 ** N - 8 ** N - (9 ** N - 8 ** N) * 2
print(ans % mod)
Problem p02684 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2 * 10 ** 5)

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

town_line = []
town_set = set()
last_town = None


def search(town=0):
    global last_town
    if town not in town_set:
        town_line.append(town)
        town_set.add(town)
        search(town=A[town]-1)
    else:
        last_town = town
        return


search(0)
town_loop = town_line[town_line.index(last_town):]

if K < len(town_line):
    print(town_line[K] + 1)
else:
    k = K - len(town_line) + 1
    k = k % len(town_loop)
    print(town_loop[k - 1] + 1)

Buggy submission (verdict: Runtime Error):
import sys

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

town_line = []
town_set = set()
last_town = None


def search(town=0):
    global last_town
    if town not in town_set:
        town_line.append(town)
        town_set.add(town)
        search(town=A[town]-1)
    else:
        last_town = town
        return


search(0)
town_loop = town_line[town_line.index(last_town):]

if K < len(town_line):
    print(town_line[K] + 1)
else:
    k = K - len(town_line) + 1
    k = k % len(town_loop)
    print(town_loop[k - 1] + 1)
Problem p02844 (python)

Fixed submission:
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN

import sys


def main():
    N = int(input())  # 桁数
    S = str(input())

    ans = set()

    digit1 = set()

    for i in range(0, N - 2):
        if S[i] in digit1:
            continue
        digit1.add(S[i])
        digit2 = set()

        for j in range(i + 1, N - 1):
            if S[j] in digit2:
                continue
            digit2.add(S[j])
            digit3 = set()
            for k in range(j + 1, N):
                if len(digit3) == 10:
                    break
                code = S[i] + S[j] + S[k]
                ans.add(code)

    print(len(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN
N = int(input())
S = str(input())

ans = 0
for i in range(10):
    code1 = S.find(str(i))
    if code1 == -1:
        continue
    for j in range(10):
        code2 = S.find(str(j), code1 + 1)
        if code2 == -1:
            continue
        for k in range(10):
            code3 = S.find(str(k), code2 + 1)
            if code3 != -1:
                ans += 1

print(ans)
b v
Problem p02882 (python)

Fixed submission:
# D
import sys
import math


# def main():
#     a, b, x = map(int, sys.stdin.readline().strip().split())
#
#     s = x / a
#     if s > a * b / 2:
#         ans = math.atan(a ** 2 / (2 * (a * b - s)))
#     else:
#         ans = math.atan(2 * s / (b ** 2))
#
#     print(90 - math.degrees(ans))

def main():
    a, b, x = map(int, sys.stdin.readline().strip().split())

    s = x / a
    if s > a * b / 2:
        ans = math.degrees(math.atan(2 * b / a - 2 * s / (a ** 2)))
        print(ans)
    else:
        ans = 90 - math.degrees(math.atan(2 * s / (b ** 2)))
        print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math


def main():
    a, b, x = map(int, sys.stdin.readline().strip().split())

    s = x / a
    if s > a * b / 2:
        # ans = math.atan(1 / (2 / a * (b - s / a)))
        ans = math.atan(a ** 2 / (2 * (a * b - s)))
    else:
        ans = math.atan(2 * s / (b ** 2))

    print(90 - math.degrees(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math


def main():
    a, b, x = map(int, sys.stdin.readline().strip().split())

    s = x / a
    if s > a * b / 2:
        ans = math.atan(1 / (2 / a * (b - s / a)))
    else:
        ans = math.atan(2 * s / (b ** 2))
        
    print(90 - math.degrees(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math


def main():
    a, b, x = map(int, sys.stdin.readline().strip().split())

    s = x / a
    if s > a * b / 2:
        ans = math.atan(1 / (2 / a * (b - s / a)))
    else:
        ans = math.atan(2 * s / (b ** 2))
        
    print(90 - math.degrees(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# D
import sys
import math


def main():
    a, b, x = map(int, sys.stdin.readline().strip().split())

    s = x / a
    if s >= a * b / 2:
        ans = math.atan(1 / (2 / a * (b - s / a)))
    else:
        ans = math.atan(2 * s / (b ** 2))
    print(90 - math.degrees(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# D
import sys
import math


def main():
    a, b, x = map(int, sys.stdin.readline().strip().split())

    s = x / a
    if s >= a * b / 2:
        ans = math.atan(1 / (2 / a * (b - s / a)))
    else:
        ans = math.atan(2 * s / (b ** 2))
    print(90 - math.degrees(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math
a, b, x = map(int, sys.stdin.readline().strip().split())

s = x / a
if s >= a * b / 2:
    ans = math.atan(1 / (2 / a * (b - s / a)))
else:
    ans = math.atan(2 * s / (b ** 2))
print(90 - math.degrees(ans))
Problem p03557 (python)

Fixed submission:
# AtCoder Beginner Contest 077 C - Snuke Festival　

import sys

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
B = list(map(int, sys.stdin.readline().strip().split()))
C = list(map(int, sys.stdin.readline().strip().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)


def search(i, S):  # i : search する数値  S: search対象の数列　　大きいものの個数を返す
    if S[0] > i:
        return len(S)
    if S[-1] <= i:
        return 0

    left = 0
    right = len(S) - 1

    while right - left != 1:
        # print(f'right:{right}, left:{left}')
        mid = int((left + right) / 2)
        if S[mid] <= i:
            left = mid
        else:
            right = mid

    return len(S) - (left + 1)


def search1(i, S):  # i : search する数値  S: search対象の数列  小さいものの個数を返す
    if S[0] >= i:
        return 0
    if S[-1] < i:
        return len(S)

    left = 0  # 満たす
    right = len(S) - 1  # 満たさない

    while right - left != 1:
        mid = int((left + right) / 2)
        if S[mid] < i:
            left = mid
        else:
            right = mid

    return left + 1


ans = 0
for b in B:
    ans_a = search1(b, A)
    ans_c = search(b, C)

    ans += ans_a * ans_c

print(ans)

Buggy submission (verdict: Runtime Error):
# AtCoder Beginner Contest 077 C - Snuke Festival　

import sys

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
B = list(map(int, sys.stdin.readline().strip().split()))
C = list(map(int, sys.stdin.readline().strip().split()))

A = sorted(A)
B = sorted(B)
C = sorted(C)


def search(i, S):  # i : search する数値  S: search対象の数列
    if S[0] > i:
        return len(S)
    if S[-1] < i:
        return 0

    left = 0
    right = len(S) - 1

    while right - left != 1:
        print(f'right:{right}, left:{left}')
        mid = int((left + right) / 2)
        if S[mid] < i:
            left = mid
        else:
            right = mid

    return len(S) - (left + 1)


ans = 0
for a in A:
    b_num = search(a, B)
    if b_num == 0:
        continue
    for b in B[-b_num:]:
        # print(f'a: {a}, b: {b}')
        c_num = search(b, C)
        # print(f'c_num: {c_num}')
        ans += c_num

print(ans)
Problem p03752 (python)

Fixed submission:
# Square869120Contest #4 B - Buildings are Colorful!　

import sys

N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))


def dfs(height=a[0], cost=0, target=K, can_see=1, i=1):
    if can_see >= target:
        # print('height', height)
        # print('can_see', can_see)
        # print('cost', cost)
        return cost

    # 端まで探索したとき
    if i == len(a):
        return float('inf')

    # 建物 i を選ばない場合
    if height >= a[i]:
        cost1 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i+1)
    else:
        cost1 = dfs(height=a[i], cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost1', cost1, 'can_see', can_see, 'i', i)

    # 建物　i を選んだ場合
    cost += max(0, height + 1 - a[i])
    height = max(a[i], height + 1)
    cost2 = dfs(height=height, cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost2', cost2)

    return min(cost1, cost2)


print(dfs(a[0], cost=0, target=K, can_see=1, i=1))

Buggy submission (verdict: Runtime Error):
# Square869120Contest #4 B - Buildings are Colorful!　
 
import sys
 
N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))

if K == 0:
  break
 
 
def dfs(height=a[0], cost=0, target=K, can_see=1, i=1):
    if can_see >= target:
        # print('height', height)
        # print('can_see', can_see)
        # print('cost', cost)
        return cost
 
    # 端まで探索したとき
    if i == len(a):
        return float('inf')
 
    # 建物 i を選ばない場合
    if height >= a[i]:
        cost1 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i+1)
    else:
        cost1 = dfs(height=a[i], cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost1', cost1, 'can_see', can_see, 'i', i)
 
    # 建物　i を選んだ場合
    cost += max(0, height + 1 - a[i])
    height = max(a[i], height + 1)
    cost2 = dfs(height=height, cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost2', cost2)
 
    return min(cost1, cost2)
 
 
print(dfs(a[0], cost=0, target=K, can_see=1, i=1))

Buggy submission (verdict: Runtime Error):
# Square869120Contest #4 B - Buildings are Colorful!　
 
import sys
 
N, K = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))

if K == 0:
  break
 
def dfs(height=a[0], cost=0, target=K, can_see=1, i=1):
    if can_see >= target:
        # print('height', height)
        # print('can_see', can_see)
        # print('cost', cost)
        return cost
 
    # 端まで探索したとき
    if i == len(a):
        return float('inf')
 
    # 建物 i を選ばない場合
    if height >= a[i]:
        cost1 = dfs(height=height, cost=cost, target=K, can_see=can_see, i=i+1)
    else:
        cost1 = dfs(height=a[i], cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost1', cost1, 'can_see', can_see, 'i', i)
 
    # 建物　i を選んだ場合
    cost += max(0, height + 1 - a[i])
    height = max(a[i], height + 1)
    cost2 = dfs(height=height, cost=cost, target=K, can_see=can_see+1, i=i+1)
    # print('cost2', cost2)
 
    return min(cost1, cost2)
 
 
print(dfs(a[0], cost=0, target=K, can_see=1, i=1))
Problem p02612 (python)

Fixed submission:
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
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
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)]

# @lru_cache(None)

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

    print(1000-n%1000)

Buggy submission (verdict: Runtime Error):

t=1
# t=int(input())
for _ in range(t):
    from bisect import bisect_left
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    m=bisect_left(a,0)
    MOD=10**9+7
    ans=1
    if m==0 or (m==n and k%2==1):
        for i in a[-k:]:
            ans=(ans*i)%MOD
    elif m==n and k%2==0:
        for i in a[:k]:
            ans=(ans*i)%MOD
    else:
        ans=1
        l,r=0,-1
        lm=a[0]*a[1]
        rm=a[-1]*a[-2]
        for i in range(k//2):
            if lm>=rm:
                ans*=lm%MOD
                l+=2
                if l<=n-2:
                    lm=a[l]*a[l+1]
            else:
                ans*=rm%MOD
                r-=2
                if 1<=n+r:
                    rm=a[r]*a[r-1]
            ans%=MOD
        if k%2==1:
            ans*=a[r]
            ans%=MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
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
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
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)]

# @lru_cache(None)

t=1
# t=int(input())
for _ in range(t):
    n=L()[0]
    print(1000-N%1000)