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

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(4100000)
def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    Q = deque([])
    visited = [[float('inf')] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                Q.append((h,w))
                visited[h][w] = 0
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    ans = 0
    while Q:
        y, x = Q.popleft()
        now = visited[y][x]
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < W and 0 <= ny < H:
                if visited[ny][nx] == float('inf'):
                    visited[ny][nx] = now + 1
                    Q.append((ny,nx))
                    ans = max(ans, now + 1)

    print(ans)




if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(4100000)
def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    Q = deque([])
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                Q.append((h,w))
    visited = [[0] * W for _ in range(H)]
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    while Q:
        x, y = Q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < W and 0 <= ny < H and not visited[ny][nx]:
                visited[ny][nx] = min(visited[y][x] + 1,visited[ny][nx])
                Q.append((ny,nx))

    ans = 0
    for h in range(H):
        ans = max(ans, max(visited[h]))

    print(ans)




if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque

def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]
    Q = deque([])
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                Q.append((h,w))
    visited = [[0] * W for _ in range(H)]
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    while Q:
        x, y = Q.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]

            if 0 <= nx < W and 0 <= ny < H and not visited[ny][nx]:
                visited[ny][nx] = visited[y][x] + 1
                Q.append((ny,nx))

    ans = 0
    for h in range(H):
        ans = max(ans, max(visited[h]))

    print(ans)




if __name__ == "__main__":
    main()
Problem p03208 (python)

Fixed submission:

N, K = map(int, input().split(" "))

h = [int(input()) for i in range(N)]

sort_h = sorted(h)
diff_h = 0
ans = []
for i in range(len(h)-K+1):
    diff_h = sort_h[i+(K-1)] - sort_h[i] 
    ans.append(diff_h)

print(min(ans))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split(" "))

h = [int(input()) for i in range(N)]

sort_h = sorted(h)
diff_h = 0
ans = []
for i in range(K):
    diff_h = sort_h[i+(K-1)] - sort_h[i] 
    ans.append(diff_h)

print(min(ans))
Problem p03253 (python)

Fixed submission:
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N, M = map(int, input().split())

    MOD = 10 ** 9 + 7
    c = collections.Counter(prime_factorize(M))
    ans = 1
    for i, j in c.items():
        ans *= cmb(N+j-1,N-1)
        ans %= MOD

    print(ans)

main()

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce
from collections import Counter

def cmb(n, r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def prime_factor(n):
    ass = []
    for i in range(2, int(n ** 0.5) + 1):
        while n  % i == 0:
            ass.append(i)
            n = n // i
    if n != i:
        ass.append(n)
    return ass

def main():
    N, M = map(int, input().split())
    num_list = prime_factor(M)
    MOD = 10 ** 9 + 7
    C = Counter(num_list)
    ans = 1
    for i, j in C.items():
        if i == 1:
            continue
        ans *= cmb(j+N-1, j)
        ans %= MOD
    print(ans)



if __name__ == "__main__":
    main()
Problem p03426 (python)

Fixed submission:
def main():
    H, W, D = map(int, input().split())
    field = [list(map(int, input().split())) for _ in range(H)]

    c = [0] * (H * W)
    for i in range(H):
        for j in range(W):
            c[field[i][j] - 1] = (i, j)
    
    d = [0] * (H * W)
    for l in range(H * W - D):
        i, j = c[l]
        x, y = c[l + D]
        d[l+D] = d[l] + abs(x - i) + abs(y - j)
    
    Q = int(input())
    for _ in range(Q):
        L, R = map(int, input().split())
        print(d[R-1]-d[L-1])


main()

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

def main():
    @lru_cache(maxsize=1000)
    def dfs(d,R,sx,sy):
        if d == R:
            return 0
        x = 0
        y = 0
        for i in range(H):
            for j in range(W):
                if A[i][j] == d + D:
                    x = i
                    y = j
                    break
            else:
                continue
            break
        
        res = abs(x - sx) + abs(y - sy) + dfs(d+D,R,x,y)

        return res
    
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    Q = int(input())

    for _ in range(Q):
        L, R = map(int, input().split())
        sx = 0
        sy = 0
        for i in range(H):
            for j in range(W):
                if A[i][j] == L:
                    sx = i
                    sy = j
                    break
            else:
                continue
            break
        print(dfs(L,R,sx,sy))

        
        
        

main()

Buggy submission (verdict: Runtime Error):
def main():
    def dfs(d,R,sx,sy):
        if d == R:
            return 0
        x = 0
        y = 0
        for i in range(H):
            for j in range(W):
                if A[i][j] == d + D:
                    x = i
                    y = j
                    break
            else:
                continue
            break
        
        res = abs(x - sx) + abs(y - sy) + dfs(d+D,R,x,y)

        return res
    
    H, W, D = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    Q = int(input())

    for _ in range(Q):
        L, R = map(int, input().split())
        sx = 0
        sy = 0
        for i in range(H):
            for j in range(W):
                if A[i][j] == L:
                    sx = i
                    sy = j
                    break
            else:
                continue
            break
        print(dfs(L,R,sx,sy))

        
        
        

main()
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def dfs(v,p,d):
    for i, j in tree[v]:
        if i != p:
            depth[i] = d + j
            dfs(i,v,d+j)

N = int(input())

tree = [[] for _ in range(N)]

for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b,c))
    tree[b].append((a,c))

Q, K = map(int, input().split())

depth = [0 for i in range(N)]
depth[K-1] = 0

dfs(K-1,-1,0)

for _ in range(Q):
    x, y = map(int, input().split())
    print(depth[x-1] + depth[y-1])

Buggy submission (verdict: Runtime Error):
def dfs(v,p,d):
    for i, j in tree[v]:
        if i != p:
            depth[i] = d + j
            dfs(i,v,d+j)

N = int(input())

tree = [[] for _ in range(N)]

for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append((b,c))
    tree[b].append((a,c))

Q, K = map(int, input().split())

depth = [0 for i in range(N)]
depth[K-1] = 0

dfs(K-1,-1,0)

for _ in range(Q):
    x, y = map(int, input().split())
    print(depth[x-1] + depth[y-1])
Problem p03776 (python)

Fixed submission:
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

def max_ave():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)

    # 平均の最大値を求める
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    # 選び方を求める
    V = sort_v[:A]
    num = v.count(min(V))
    a = V.count(min(V))
    cnt = 0
    if max(V) == min(V):
        for i in range(A,B+1):
            if num < i:
                continue
            cnt += combinations_count(num,i)
    else:
        cnt = combinations_count(num,a)
    
    print(cnt)

max_ave()

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def main():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)
    ave = 0
    ans = 0
    if sort_v[0] == sort_v[A-1]:
        cnt = v.count(sort_v[A-1])
        ave = sort_v[0]
        for i in range(A, min(cnt,B)+1):
            ans += cmb(cnt,i)
    else:
        cnt = v.count(sort_v[A-1])
        ind = sort_v.index(sort_v[A-1])
        for i in range(ind, A):
            ans += cmb(cnt, i)
        tmp = 0
        for i in range(A):
            tmp += sort_v[i]
        ave = tmp / A
    print(ave)
    print(ans)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

def max_ave():
    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    sort_v = sorted(v, reverse=True)

    # 平均の最大値を求める
    sum_A = 0
    for i in range(A):
        sum_A += sort_v[i]
    max_ave_v = sum_A / A

    print(max_ave_v)

    # 選び方を求める
    V = sort_v[:A]
    num = v.count(min(V))
    a = V.count(min(V))
    cnt = 0
    if max(V) == min(V):
        if num == 1:
            print(1)
            exit()
        for i in range(A,B+1):
            cnt += combinations_count(num,i)
    else:
        cnt = combinations_count(num,a)
    
    print(cnt)

max_ave()
Problem p02693 (python)

Fixed submission:
K = int(input())
A, B = map(int, input().split())

for i in range(A, B+1):
    if i % K == 0:
        print('OK')
        exit(0)
print('NG')

Buggy submission (verdict: Runtime Error):
import math

A, B, N = map(int, input().split())

ans = 0
if N == max(A, B, N):
    ans = math.floor((A*N)/B)-A*(N//B)
else:
    if N <= 1000000:
        for x in range(1, N+1):
            tmp = math.floor((A*x)/B)-A*(x//B)
            ans = max(ans, tmp)
    else:
        for x in range(1, 300000):
            tmp = math.floor((A*x)/B)-A*(x//B)
            ans = max(ans, tmp)

        base = N//2-150000
        for x in range(base, base+300000):
            tmp = math.floor((A*x)/B)-A*(x//B)
            ans = max(ans, tmp)

        for x in range(N-300000, N+1):
            tmp = math.floor((A*x/B))-A*(x//B)
            ans = max(ans, tmp)
print(int(ans))
Problem p02859 (python)

Fixed submission:
r = int(input())
print(r*r)

Buggy submission (verdict: Runtime Error):
r=list(input())
print(r*r)
Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())

# S単体で必要な置換数を求める
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)

# Sを接続した時に必要な置換数を求める
s3 = S*3
cnt_1 = 0
for i in range(len(s3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)

# 単体と接続時に必要な置換数の合計を求める
ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

# S単体で必要な置換数を求める
cnt = 0
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 0.5
    else:
        cnt = int(cnt+0.5)
cnt = int(cnt+0.5)

# Sを接続した時に必要な置換数を求める
s3 = S*3
cnt_1 = 0
for i in range((len(s3)*3)-1):
    if s3[i] == s3[i+1]:
        cnt_1 += 0.5
    else:
        cnt_1 = int(cnt_1+0.5)
cnt_1 = int(cnt_1+0.5)

# 単体と接続時に必要な置換数の合計を求める
ans = int((cnt_1-cnt*3)/2*(K-1)+0.5)+cnt*K
print(ans)
Problem p02948 (python)

Fixed submission:
import heapq

N, M = map(int, input().split())
AB = [[] for i in range(10**5+1)]

for i in range(N):
    A, B = map(int, input().split())
    AB[A].append(-B)

hq = []
heapq.heapify(hq)

ans = 0
for i in range(1, M+1):
    for b in AB[i]:
        heapq.heappush(hq, b)

    if len(hq) > 0:
        ans += -heapq.heappop(hq)

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

N, M = map(int, input().split())
AB = [[] for i in range(10*5+1)]

for i in range(N):
    A, B = map(int, input().split())
    AB[A].append(-B)

hq = []
heapq.heapify(hq)

ans = 0
for i in range(1, M+1):
    for a in AB[i]:
        heapq.heappush(hq, a)

    if len(hq) > 0:
        ans += abs(heapq.heappop(hq))

print(ans)
Problem p03038 (python)

Fixed submission:
n, m = map(int, input().split())
A = list(map(int, input().split()))

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if index >= n:
        break
    elif A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if index >= n:
            break
        elif A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if index >= n:
        break
    elif A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = list(map(int, input().split()))

CB = []
for _ in range(m):
    b, c = map(int, input().split())
    CB.append([c, b])

CB.sort(reverse=True)
A.sort()
index = 0
for i in range(m):
    if A[index] >= CB[i][0]:
        break

    for j in range(CB[i][1]):
        if A[index] >= CB[i][0]:
            break

        A[index] = CB[i][0]
        index += 1

print(sum(A))
Problem p03127 (python)

Fixed submission:
import fractions

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1, N):
    ans = fractions.gcd(ans, A[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
A = list(map(int, input().split()))

ans = A[0]
for i in range(1, N):
    ans = math.gcd(ans, A[i])
print(ans)
Problem p03208 (python)

Fixed submission:
n, k = map(int, input().split())

hl = []
for _ in range(n):
    hl.append(int(input()))

hl.sort()

ans = 10**9+1
for i in range(len(hl)-k+1):
    ans = min(ans, hl[i+k-1]-hl[i])

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)


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


N, K = map(int, input().split())
H = [0]*N
for i in range(N):
    H[i] = int(input())

H.sort()
ans = 10**10
for i in range(N-(K-1)):
    ans = min(ans, max(H[i], H[i+1], H[i+2])-min(H[i], H[i+1], H[i+2]))
print(ans)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(200000)


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


# Kから順に探索して、Kからの距離を求める
def dfs(v, parent=-1, distance=0):
    # Kから現在の位置までの距離を記録する
    sum_distance[v] = distance
    for i, j in tree[v]:
        if i == parent:
            continue
        dfs(i, v, distance+j)


N = int(input())

tree = [[] * N for i in range(N)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append([b, c])
    tree[b].append([a, c])

Q, K = map(int, input().split())

# 事前に各頂点から頂点Kまでの距離を求める
sum_distance = [0]*N
dfs(K-1)

# クエリを処理する。xからKまでとyからKまでの距離の合計を求める
for _ in range(Q):
    x, y = map(int, input().split())
    print(sum_distance[x-1]+sum_distance[y-1])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)


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


def dfs(now, point):
    if K in tree[now-1]:
        point += tree_c[now-1][K]
        return point
    else:
        for next_node in tree[now-1]:
            if zumi[next_node-1] == -1:
                tmp_p = point+tree_c[now-1][next_node]
                return dfs(next_node, tmp_p)


N = int(input())
tree = [{} for i in range(N)]
tree_c = [{} for i in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    tree[a-1][b] = True
    tree[b-1][a] = True
    tree_c[a-1][b] = c
    tree_c[b-1][a] = c
Q, K = map(int, input().split())

for _ in range(Q):
    x, y = map(int, input().split())
    zumi = [-1]*N
    zumi[x-1] = 0
    ans = dfs(x, 0)

    zumi = [-1]*N
    zumi[y-1] = 0
    ans += dfs(y, 0)
    print(ans)
Problem p02711 (python)

Fixed submission:
string = input()
found = False
for i in string:
  if i == '7':
    found=True
    break
    
    
if found:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
t=int(input())
S=0
for i in list(range(t+1)):
  if i%5!=0 and i%3!=0:
    sum += i
print(S)
Problem p02712 (python)

Fixed submission:
t=int(input())
S=0
for i in list(range(t+1)):
  if i%5!=0 and i%3!=0:
    S += i
print(S)

Buggy submission (verdict: Runtime Error):
t=int(input())
S=0
for i in list(range(t+1)):
  if t%5!=0 and t%3!=0:
    sum += i
print(S)

Buggy submission (verdict: Runtime Error):
t=int(input())
S=0
for i in range(t):
  if t%5!=0 and t%3!=0:
    sum += 1
print(S)
Problem p03242 (python)

Fixed submission:
l=list(input())
for i in range(len(l)):
  if l[i]=='1':
    l[i]='9'
  elif l[i]=='9':
    l[i]='1'
print(''.join(l))

Buggy submission (verdict: Runtime Error):
l=list(input())
for i in range(len(l)):
  if l[i]=='1':
    l[i]='9'
  elif l[i]=='9':
    l[i]='1'
print ''.join(l)
Problem p02661 (python)

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A,B=[0]*n,[0]*n
    for i in range(n):
        A[i],B[i]=map(int,input().split())
    A.sort()
    B.sort()
    if n%2==1:
        print(B[n//2]-A[n//2]+1)
    else:
        print(int(((B[n//2-1]+B[n//2])/2-(A[n//2-1]+A[n//2])/2)*2)+1)

if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w,k=map(int,input().split())
    S=[input() for _ in range(h)]
    final_ans=10**10
    for row_lis in range(1<<(h-1)):
        lst=[0]*h
        q,ans=0,0
        for r in range(h-1):
            if (row_lis>>r)&1==0:
                lst[r+1]=q
            else:
                q+=1
                lst[r+1]=q
                ans+=1
        data=[0]*h
        for j in range(w):
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    ans+=1
                    break
            else:
                continue
            data=[0]*h
            for i in range(h):
                data[lst[i]]+=int(S[i][j])
                if data[lst[i]]>k:
                    break
            else:
                continue
            break
        else:
            final_ans=min(final_ans,ans)
    print(final_ans)


if __name__=='__main__':
    main()
Problem p02729 (python)

Fixed submission:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int,input().split())
if n>=2 and m>=2:print(cmb(n,2)+cmb(m,2))
elif n>=2:print(cmb(n,2))
elif m>=2:print(cmb(m,2))
else:print(0)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int,input().split())
if n>=2 and m>=2:print(cmb(n,2)+cmb(m,2))
elif n>=2:print(cmb(m,2))
elif m>=2:print(cmb(n,2))
else:print(0)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int,input().split())
if n>=2 and m>=2:print(cmb(n,2)+cmb(m,2))
elif n=>2:print(cmb(m,2))
elif m>=2:print(cmb(n,2))
else:print(0)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,m=map(int,input().split())
if n>=2 and m>=2:print(cmb(n,2)+cmb(m,2))
elif n==1 and m==1:print(0)
elif m==1:print(cmb(n,2))
else:print(cmb(m,2))
Problem p02847 (python)

Fixed submission:
s=["SUN","MON","TUE","WED","THU","FRI","SAT"]
print(7-int(s.index(input())))

Buggy submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,x=map(int,input().split())
    if a+b>x:
        print(0)
        sys.exit()
    for i in range(9,0,-1):#d(N)
        if x-b*i<a*10**(i-1):
            continue
        print(min(10**9,(x-b*i)//a))
        sys.exit()

if __name__=='__main__':
    main()
Problem p02862 (python)

Fixed submission:
import sys
def input(): return sys.stdin.readline().rstrip()
from functools import reduce
def mod_comb4(n,r,mod=10**9+7):
    if r==1:return n
    elif r==0:return 1
    else:
        num=reduce(lambda x,y:x*y%mod,range(n,n-r,-1))
        den=reduce(lambda x,y:x*y%mod,range(1,r+1))
        return num*pow(den,mod-2,mod)%mod
def main():
    x,y=map(int,input().split())
    mod=10**9+7
    n=2*x-y
    m=2*y-x
    if n%3==0 and m%3==0 and n>=0 and m>=0:
        print(mod_comb4(n//3+m//3,n//3,mod))
    else:
        print(0)


if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()
from functools import reduce
def mod_comb4(n,r,mod=10**9+7):
    if r==1:return n
    elif r==0:return 1
    else:
        num=reduce(lambda x,y:x*y%mod,range(n,n-r,-1))
        den=reduce(lambda x,y:x*y%mod,range(1,r+1))
        return num*pow(den,mod-2,mod)%mod
def main():
    x,y=map(int,input().split())
    mod=10**9+7
    if (2*x-y)%3>0 or (2*y-x)%3>0:
        print(0)
    else:
        n=(2*x-y)//3
        m=(2*y-x)//3
        print(mod_comb4(n+m,n,mod)%mod)


if __name__=='__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
def input(): return sys.stdin.readline().rstrip()
from functools import reduce
def mod_comb4(n,r,mod=10**9+7):
    num=reduce(lambda x,y:x*y%mod,range(n,n-r,-1))
    den=reduce(lambda x,y:x*y%mod,range(1,r+1))
    return num*pow(den,mod-2,mod)%mod
def main():
    x,y=map(int,input().split())
    mod=10**9+7
    if (2*x-y)%3>0 or (2*y-x)%3>0:
        print(0)
    else:
        n=(2*x-y)//3
        m=(2*y-x)//3
        print(mod_comb4(n+m,n,mod)%mod)


if __name__=='__main__':
    main()