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

Fixed submission:
def memorize(func):
    memo = {}
    def wrapper(*args):
        if args not in memo:
            memo[args] = func(*args)
        return memo[args]
    return wrapper
def factorize(n, factor=2, index=0):
    counter = 0
    while True:
        if n%factor==0:
            n //=factor
            counter += 1
        else:
            break
    if counter>0:
        yield (factor, counter)
    if factor**2 < n:
        yield from factorize(n, factor+1)
    elif n>2:
        yield (n, 1)
@memorize
def choose(N, M):
    if M>N:
        return 0
    if N==0 or M==0:
        return 1
    else:
        return N*choose(N-1, M-1)//M
def ans(N, M):
    val = 1
    for _, r in factorize(M):
        val *= choose(N+r-1, r)
        val %= (10**9+7)
    return val
import sys; sys.setrecursionlimit(100000)
print(ans(*map(int, input().split())))

Buggy submission (verdict: Runtime Error):
def gen_to_list(func):
    def wrapper(*args):
        return list(func(*args))
    return wrapper
def memorize(func):
    memo = {}
    def wrapper(*args):
        if args not in memo:
            memo[args] = func(*args)
        return memo[args]
    return wrapper
@gen_to_list
def factorize(n, factor=2, index=0):
    counter = 0
    while True:
        if n%factor==0:
            n //=factor
            counter += 1
        else:
            break
    if counter>0:
        yield (factor, counter)
    if factor**2 < n:
        yield from factorize(n, factor+1)
    elif n>2:
        yield (n, 1)
@memorize
def choose(N, M):
    if M>N:
        return 0
    if N==0 or M==0:
        return 1
    else:
        return N*choose(N-1, M-1)//M
def ans(N, M):
    val = 1
    for _, r in factorize(M):
        val *= choose(N+r-1, r)
        val %= (10**9+7)
    return val
print(ans(*map(int, input().split())))
Problem p02629 (python)

Fixed submission:
N=int(input())
l = int(N**(1/26))
name = ''
while N >0:
    N -= 1
    r = N%26
    N = N//26
    name += chr(ord('a')+r)
print(name[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input()) 
name='' 
while N>0:
    N -= 1
    ans += chr(ord('a') + N % 26)
    N = N // 26
print(name[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input()) 
name='' 
while N>0:
    N -= 1
    ans += chr(ord('a') + N % 26)
    N //= 26
print(name[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input()) 
name='' 
while N>0:
    N -= 1
    ans += chr(ord('a') + N % 26)
    N //= 26
print(name[::-1])
Problem p02754 (python)

Fixed submission:
n, b, r = map(int,input().split())
 
rep = n // (b+r)
mod = n % (b+r)
ans = rep * b
 
if mod > b:
	ans+= b  
else:
    ans+= mod
print(ans)

Buggy submission (verdict: Runtime Error):
n, b, r = map(int,input().split())

rep = n // (a+b)
mod = n % (a+b)
ans = rep * b

if mod > a:
	ans+= a  
else:
    ans+= mod
print(ans)
Problem p02623 (python)

Fixed submission:
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a,b=[0],[0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

ans=0
j=m
for i in range(n+1):
    if a[i]>k:
        break
    time=a[i]+b[j]
    while time>k:
        j-=1
        time=a[i]+b[j]
    ans=max(ans,i+j)
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
sum=0
while sum<=k and (A!=[] or B!=[]):
    if A!=[] and B!=[]:
        a=A[0]
        b=B[0]
        if a<b or B==[]:
            sum+=A.pop(0)
            ans+=1
        elif b<a and A==[]:
            sum+=B.pop(0)
            ans += 1
        else:
            x=min(len(A),len(B))
            for i in range(x):
                if A[i]<B[i]:
                    sum += A.pop(0)
                    ans += 1
                    break
                elif A[i]>B[i]:
                    sum += B.pop(0)
                    ans += 1
                    break
            if len(A)>len(B):
                if A[i+1]>B[i]:
                    sum += B.pop(0)
                    ans += 1
                else:
                    sum += A.pop(0)
                    ans += 1
    elif A!=[]:
        sum += A.pop(0)
        ans += 1
    elif B!=[]:
        sum += B.pop(0)
        ans += 1
if sum>k:
    print(ans-1)
else:
    print(ans)
Problem p02862 (python)

Fixed submission:
x, y = map(int, input().split())
mod = 10**9+7 
def check(x, y):
  if (2*y-x)/3 < 0 or (2*x -y)/3 < 0:
    return False
  if (x+y)%3 != 0:
    return False
  return True

def comb(n, r, mod):
    r = min(r, n-r)
    x, y  = 1, 1
    for i in range(1, r+1):
      y =  y* i % mod
      x =  x* (n+1-i) % mod
    return x * pow(y, mod-2, mod) % mod
  
if check(x, y):
  print(comb((2*y-x)//3+(2*x -y)//3, (2*y-x)//3, mod))
else:
  print(0)

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())
mod = 10**9+7 
def check(x, y):
  if (2*y-x)/3 < 0 or (2*x -y)/3 < 0:
    return False
  if (x+y)%3 != 0:
    return False
  return True

def comb(n, r, mod):
    r = min(r, n-r)
    x, y  = 1, 1
    for i in range(1, r+1):
      y =  y* i % mod
      x =  x* (n+1-i) % mod
    return int(x * pow(y, mod-2, mod) % mod)
  
if check(x, y):
  print(comb((2*y-x)//3+(2*x -y)/3, (2*y-x)//3, mod))
else:
  print(0)
Problem p03745 (python)

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

flag = 0
 
ans = 1
for i in range(n - 1):
  if flag == 1:
    if a[i] > a[i + 1]:
      ans += 1
      flag = 0
  elif flag == -1:
    if a[i] < a[i + 1]:
      ans += 1
      flag = 0
  else:
    if a[i] > a[i + 1]:
      flag = -1
    elif a[i] < a[i + 1]:
      flag = 1
print(ans)

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

count = 0
flag = False

if a[0] >= a[1]:
  flag = True
else:
  flag = False
  
for i in range(1, n-1):
  if a[i] == a[i+1]:
    break
  elif a[i] > a[i+1]:
    if not flag:
      count+=1
      flag = False
  else:
    if flag:
      count+=1
      flag = True
print(count+1)
Problem p02753 (python)

Fixed submission:
S=input()
if S[0]==S[1]and S[1]==S[2]:
	print('No')
else:
	print('Yes')

Buggy submission (verdict: Runtime Error):
S=input()
if not S[1]==S[2]and S[2]==S[3]:
	print('No')
else:
	print('Yes')

Buggy submission (verdict: Runtime Error):
S[3]
S[1]=input()
S[2]=input()
S[3]=input()
if not S[1]==S[2]and S[2]==S[3]:
	print('No')
else:
	print('Yes')
Problem p02693 (python)

Fixed submission:
n = int(input())
a, b = map(int, input().split())
for i in range(a, b + 1, 1):
  if(i % n == 0):
    print('OK')
    exit()
print('NG')

Buggy submission (verdict: Runtime Error):
n = int(input())
a, b = map(int, input().split())
for i in range(a, b + 1):
	if(i % k == 0):
    	print('OK')
        exit()
print('NG')
Problem p02779 (python)

Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]
if(n > len(set(a))):	print('NO')
else:	print('YES')

Buggy submission (verdict: Runtime Error):
input()
a = [int(x) for x in iput().split()]
if(len(set(a)) < len(a)):
  print('YES')
else:
  print('NO')
Problem p03201 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in d:
        d[A[i]] += 1
    else:
         d[A[i]] = 1

for i in range(N):
    t = 2**len(bin(A[i])[2::]) - A[i]
    if t in d:
        if t != A[i]:
            if d[t]>0 and d[A[i]]>0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1
        else:
            if d[t] > 1:
                ans2 += 1
                d[t] -= 2


print(ans1+ans2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

ans1, ans2 = 0,0

maxA = max(A)
B = [1]
t = 1
while t < maxA:
    t *= 2
    B.append(t)

d = dict()
for i in range(N):
    if A[i] in B:
        ans1 += 1
        M -= 1
    else:
        if A[i] in d:
            d[A[i]] += 1
        else:
            d[A[i]] = 1

for i in range(N):
    if A[i] not in B:
        t = 2**len(bin(A[i])[2::]) - A[i]
        if t in d:
            if d[t] > 0:
                ans2 += 1
                d[t] -= 1
                d[A[i]] -= 1

print(ans1+ans2)
Problem p03286 (python)

Fixed submission:
N = int(input())

A,S = [0]*32,[0]*32
A[0],A[1],S[0],S[1] = 1,-2,1,-2
for i in range(2,32):
    A[i] = A[i-1]*(-2)
    S[i] = S[i-2] + A[i]

X = ["0"]*32
t = 0
flg = True
while N != 0:
    if N > 0:
        for i in range(32):
            if S[i] >= N:
                break
    else:
        for i in range(32):
            if S[i] <= N:
                break
    X[i] = "1"
    N -= A[i]

print(int("".join(X)[::-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())

Ans = 0
while N!=0:
    Ans = str(N%2) +Ans
    N = (N - N%2)//2
    N *= -1

print(Ans)
Problem p03345 (python)

Fixed submission:
A,B,C,K = map(int,input().split())
Ans = 0
if K%2==1:
    Ans = B-A
else:
    Ans = A-B
print(Ans if Ans <= 10**18 else "Unfair")

Buggy submission (verdict: Runtime Error):
A,B,C,K = map(int,input().split())
Ans = 0
if K%2==1:
    Ans = (B-A
else:
    Ans = A-B
print(Ans if Ans <= 10**18 else "Unfair")
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
X = [[] for _ in range(N)]

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

cost = [-1]*N
def calc(i,c):
    # 指定の頂点までのコストを代入
    cost[i] = c
    # 頂点から移動できる頂点があれば
    for ni,nc in X[i]:
        # 初期状態のままなら計算
        if cost[ni] == -1:
            calc(ni,c+nc)

Q,K = map(int,input().split())
# 事前計算
calc(K-1,0)

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

Buggy submission (verdict: Runtime Error):
def dfs(n,p,d):
    visited[n] = True
    dist[n] = d
    for (i,c) in A[n]:
        if i != p and not visited[i]:
            dfs(i,n,d+c)

N = int(input())
A = [[] for _ in range(N)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    A[a-1].append((b-1,c))
    A[b-1].append((a-1,c))
Q,K = map(int,input().split())
B = []
for _ in range(Q):
    x,y = map(int,input().split())
    B.append((x,y))

dist = [-1]*N
visited = [False]*N
dfs(K-1,N,0)

for (x,y) in B:
    print(dist[x-1]+dist[y-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [[] for _ in range(N)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    X[a-1].append((b-1,c))
    X[b-1].append((a-1,c))

cost = [-1]*(N+2)
def calc(i,c):
    # 指定の頂点までのコストを代入
    cost[i] = c
    # 頂点から移動できる頂点があれば
    for ni,nc in X[i]:
        # 初期状態のままなら計算
        if cost[ni] == -1:
            calc(ni,c+nc)

Q,K = map(int,input().split())
# 事前計算
calc(K-1,0)

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

Fixed submission:
s=input()
t=input()
print(sum([1 for index,char in enumerate(s) if t[index]!=char]))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
print(sum([1 for index,char in enumerate(s) if p[index]!=char]))
Problem p02623 (python)

Fixed submission:
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_sum = [0]
    b_sum = [0] 

    max_counter = 0

    j = m

    for i in range(n):
        a_sum.append(a_sum[i] + a[i])

    for i in range(m):
        b_sum.append(b_sum[i] + b[i])

    for i in range(n + 1):
        if a_sum[i] > k:
            break

        while k < a_sum[i] + b_sum[j]:
            j -= 1
        
        max_counter = max(max_counter, i + j)

    print(max_counter)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    a_sum = [0 for x in range(n)]
    b_sum = [0 for x in range(m)]

    a_sum[0] = a[0]
    b_sum[0] = b[0]

    max_counter = 0

    for i in range(1, n):
        a_sum[i] = a[i] + a_sum[i - 1]

    for i in range(1, n):
        b_sum[i] = b[i] + b_sum[i - 1]

    for i in range(n):
        for j in range(m):
            if k >= a_sum[i] + b_sum[j] and max_counter < i + j + 2:
                max_counter = i + j + 2
        
    print(max_counter)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
max_counter = 0

def check(limit, a, b, i, j, counter):
    global max_counter

    if len(a) > i:
        if limit - a[i] >= 0:

            check(limit - a[i], a, b, i + 1, j, counter + 1)

    if len(b) > j:
        if limit - b[j] >= 0:

            check(limit - b[j], a, b, i, j + 1, counter + 1)

    if counter > max_counter:
        max_counter = counter

    return

def main():
    global max_counter
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    check(k, a, b, 0, 0, 0)

    print(max_counter)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
max_counter = 0

def check(limit, a, b, i, j, counter):
    global max_counter
    
    if len(a) > i:
        if limit - a[i] >= 0:

            check(limit - a[i], a, b, i + 1, j, counter + 1)

            if counter > max_counter:
                max_counter = counter

    if len(b) > j:
        if limit - b[j] >= 0:

            check(limit - b[j], a, b, i, j + 1, counter + 1)

            if counter > max_counter:
                max_counter = counter

    return

def main():
    global max_counter
    n, m, k = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    check(k, a, b, 0, 0, 1)

    print(max_counter)

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

Fixed submission:
n,m=map(int,input().split())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(m):
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
ans=0
for v in range(1,n+1):
 for u in g[v]: #i番目の展望台から1本の道を通っていけるすべての展望台と高さを比較する
   if arr[u]>=arr[v]:
     break
 else: #i番目の展望台の高さが他のすべての展望台の高さより真に大きければ答えを1増やす
   ans+=1
print(ans)

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

road_num = list(map(int, input().split()))
road_num = len(road_num)

way_list = []
goal_list = []

for i in range(road_num - 1):
    way, goal = map(int, input().split())
    if not(way in way_list):
        way_list.append(way)
    if not(goal in way_list) and not(goal in goal_list):
        goal_list.append(goal)

print(len(goal_list))
Problem p02699 (python)

Fixed submission:
s, w = map(int, input().split())

if s  <= w:
    print('unsafe')
else:
    print('safe')

Buggy submission (verdict: Runtime Error):
s = str(input())
count = 0
s_len = len(s)
for i in range(s_len - 4):
    for j in range(i + 4, s_len + 1):
        if int(s[i:j]) % 2019 == 0:
            count += 1
print(count)
Problem p02629 (python)

Fixed submission:
import string
lc = string.ascii_lowercase
n = int(input())

lst = [0]
for i in range(1, 100000):
    tmp = pow(26, i)
    lst.append(tmp)
    if tmp > n:
        break
cum = [lst[0]]
for i in range(1, len(lst)):
    cum.append(cum[-1] + lst[i])
idx = 0
while True:
    if n-1 < cum[idx]:
        break
    idx += 1
num = n - cum[idx-1] - 1
ans = ''
for i in range(idx)[::-1]:
    tmp = pow(26, i)
    k = num // tmp
    num = num - tmp *k
    ans += lc[k]
print(ans)

Buggy submission (verdict: Runtime Error):
import string
lc = string.ascii_lowercase
n = int(input())

lst = [0]
for i in range(1, 1000):
    tmp = pow(26, i)
    lst.append(tmp)
    if tmp > n:
        break
cum = [lst[0]]
for i in range(1, len(lst)):
    cum.append(cum[-1] + lst[i])
idx = 0
while True:
    if n-1 < cum[idx]:
        break
    idx += 1
num = n - lst[idx-1] - 1
ans = ''
for i in range(idx)[::-1]:
    tmp = pow(26, i)
    if num >= tmp:
        k = num // tmp
        num = num - 26*k
    else:
        k = num
    ans += lc[k]
print(ans)
Problem p02685 (python)

Fixed submission:
class Cmb:
    def __init__(self, N, mod=998244353):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=998244353):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

n,m,k = map(int,input().split())
mod = 998244353
ans = 0
c = Cmb(N=n, mod=mod)
for x in range(k+1):
    if x==0:
        ans += m*pow(m-1, n-1, mod)
        ans %= mod
    else:
        ans += m*pow(m-1, n-1-x, mod)*c(n-1, x)%mod
        ans %= mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
class Cmb:
    def __init__(self, N, mod=998244353):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=10**9+7):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

n,m,k = map(int,input().split())
mod = 998244353
ans = 0
c = Cmb()
for x in range(k+1):
    if x==0:
        ans += m*pow(m-1, n-1, mod)
        ans %= mod
    else:
        ans += m*pow(m-1, n-1-x, mod)*c(n-1, x)%mod
        ans %= mod
print(ans%mod)
Problem p02781 (python)

Fixed submission:
n = input()
k = int(input())

# dp[i桁まで][非0個数][未満フラグ]
dp = [[[0]*2 for _ in range(k+1)] for _ in range(len(n)+1)]
dp[0][0][0] = 1

for i in range(len(n)):
    x = int(n[i])
    for j in range(k):
        dp[i+1][j+1][1] += dp[i][j][1]*9
        dp[i+1][j][1] += dp[i][j][1]
        if x>0:
            dp[i+1][j][1] += dp[i][j][0]
            dp[i+1][j+1][1] += dp[i][j][0]*(x-1)
            dp[i+1][j+1][0] += dp[i][j][0]
        else:
            dp[i+1][j][0] += dp[i][j][0]
    dp[i+1][k][1] += dp[i][k][1]
    dp[i+1][k][x>0] += dp[i][k][0]

print(sum(dp[len(n)][k]))

Buggy submission (verdict: Runtime Error):
def comb(x,y):
    if y==1:
        return x
    elif y==2:
        return max(x*(x-1)//2, 0)
    elif y==3:
        return max(x*(x-1)*(x-2)//6, 0)


n = int(input())
k = int(input())
digit = len(str(n))
ans1 = comb(digit-1, k) * (9**k)
lst = [int(i) for i in list(str(n))]
if k==1:
    ans2 = lst[0]
elif k==2:
    ans2 = 0
    ans2 += (lst[0]-1) * (digit-1) * 9
    ans2 += lst[1] + (digit-2)*9
elif k==3:
    ans2 = 0
    ans2 += (lst[0]-1) * comb(digit-1, 2) * (9*2)
    ans2 += lst[1]*(digit-2)*9 + comb(digit-2, 2)*(9**2)
print(ans1+ans2)

Buggy submission (verdict: Runtime Error):
def comb(x,y):
    if y==1:
        return x
    elif y==2:
        return max(x*(x-1)//2, 0)
    elif y==3:
        return max(x*(x-1)*(x-2)//6, 0)


n = int(input())
k = int(input())
digit = len(str(n))

ans1 = comb(digit-1, k) * (9**k)

lst = [int(i) for i in list(str(n))]
if k==1:
    ans2 = lst[0]
elif k==2:
    ans2 = 0
    ans2 += (lst[0]-1) * (digit-1) * 9
    ans2 += lst[1] + (digit-2)*9
elif k==3:
    ans2 = 0
    ans2 += (lst[0]-1) * comb(digit-1, 2) * (9**2)
    ans2 += lst[1]*(digit-2)*9 + comb(digit-2, 2)*(9**2)
    
print(ans1+ans2)
Problem p02862 (python)

Fixed submission:
x,y = map(int,input().split())
mod = 10**9 + 7
if (x+y)%3 != 0:
    print(0)
    exit()
n = (x+y)//3
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a == 0 or b == 0:
    print(1)
    exit()
if a < 0 or b < 0:
    print(0)
    exit()
MAX = 700000
fac = [1,1] + [0] * MAX     #累積積
finv = [1,1] + [0] * MAX    #modにおける逆元
inv = [0,1] + [0] * MAX     #invの累積積
for i in range(2,MAX):
    fac[i] = fac[i-1] * i % mod
    inv[i] = -inv[mod%i] * (mod//i)%mod
    finv[i] = finv[i-1] * inv[i]%mod


def nCr(n,r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fac[n] * (finv[r] * finv[n-r]%mod)%mod

print(nCr(n,a))

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
mod = 10**9 + 7
if (x+y)%3 != 0:
    print(0)
    exit()
n = (x+y)//3
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a == 0 or b == 0:
    print(1)
    exit()
if a < 0 or b < 0:
    print(0)
    exit()
MAX = 10
fac = [1,1] + [0] * MAX
finv = [1,1] + [0] * MAX
inv = [0,1] + [0] * MAX
for i in range(2,MAX):
    fac[i] = fac[i-1] * i % mod
    inv[i] = -inv[mod%i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i]%mod


def nCr(n,r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fac[n] * (finv[r] * finv[n-1]%mod)%mod

print(nCr(n,a))

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
mod = 10**9 + 7
if (x+y)%3 != 0:
    print(0)
    exit()
n = (x+y)//3
a = (2 * x - y) // 3
b = (2 * y - x) // 3
if a == 0 or b == 0:
    print(1)
    exit()
if a < 0 or b < 0:
    print(0)
    exit()
MAX = 10
fac = [1,1] + [0] * MAX     #累積積
finv = [1,1] + [0] * MAX    #modにおける逆元
inv = [0,1] + [0] * MAX     #invの累積積
for i in range(2,MAX):
    fac[i] = fac[i-1] * i % mod
    inv[i] = -inv[mod%i] * (mod//i)%mod
    finv[i] = finv[i-1] * inv[i]%mod


def nCr(n,r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fac[n] * (finv[r] * finv[n-1]%mod)%mod

print(nCr(n,a))

Buggy submission (verdict: Runtime Error):
mod = 10**9 + 7
x,y = map(int,input().split())
dp = [[0]*(y+3) for _ in range(x+3)]
dp[0][0] = 1

for i in range(x+1):
    for j in range(y+1):
        if dp[i][j] >= mod:
            dp[i][j] %= mod
        if dp[i][j] == 0:
            continue
        else:
            if i+2 <= x+1 and j+1 <= y+1:
                dp[i+2][j+1] += dp[i][j]
            if i+1 <= x+1 and j+2 <= y+1:
                dp[i+1][j+2] += dp[i][j]
print(dp[x][y])
Problem p02948 (python)

Fixed submission:
import heapq
n,m = list(map(int,input().split()))
jobs = [[] for _ in range(m)]
for i in range(n):
    d,r = list(map(int,input().split()))
    if d-1 < m:
        jobs[d-1].append(-r)
rewords = 0
heap = []
for i in range(m):
    for reword in jobs[i]:
        heapq.heappush(heap,reword)
    if len(heap) > 0:
        reword = heapq.heappop(heap)
        rewords += -reword
print(rewords)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(n)]

lst.sort(key = lambda x:x[0],reverse = True)
lst.sort(key = lambda x:x[1],reverse = True)

done = [0 for _ in range(n)]
gain = 0

for i in reversed(range(1,m+1)): #i:残り日数
    for j in range(n): #j:候補から優先度順で探索
        if lst[j][0] <= i and done[j] == 0: #必要な日数>残り日数 かつ undone
            gain += lst[j][1]
            done[j] = 1　#undone:0,done:1として分類
            break #働いたら次の日へ

print(gain)