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

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

b = format(B, 'b')
num = len(b)
cnt1 = [0]*num
for i in range(1, num):
    if (B+1)%(2**(i+1)) <= 2**i:
        continue
    else:
        if (B+1)%2 == 1:
            cnt1[i] = 1
if B % 4 == 1 or B % 4 == 2:
    cnt1[0] = 1

c = ''
if A == 0:
    for i in range(num):
        if cnt1[i] == 0:
            c = '0' + c
        else:
            c = '1' + c
    print(int(c, 2))
    sys.exit()

cnt2 = [0]*num
for i in range(1, num):
    if A%(2**(i+1)) <= 2**i:
        continue
    else:
        if A%2 == 1:
            cnt2[i] = 1
if (A-1) % 4 == 1 or (A-1) % 4 == 2:
    cnt2[0] = 1

for i in range(num):
    if cnt1[i] == cnt2[i]:
        c = '0' + c
    else:
        c = '1' + c
print(int(c, 2))

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
import sys
b = format(B, 'b')
num = len(b)

cnt1 = [0]*num
for i in range(1, num):
    if (B+1)%(2**(i+1)) <= 2**i:
        continue
    else:
        if (B+1)%2 == 1:
            cnt1[i] = 1
if B % 4 == 1 or B % 4 == 2:
    cnt[0] = 1

c = ''
if A == 0:
    for i in range(num):
        if cnt1[i] == 0:
            c = '0' + c
        else:
            c = '1' + c
    print(int(c, 2))
    sys.exit()

if A == B:
    print(0)
    sys.exit()

cnt2 = [0]*num
for i in range(1, num):
    if A%(2**(i+1)) <= 2**i:
        continue
    else:
        if A%2 == 1:
            cnt2[i] = 1
if (A-1) % 4 == 1 or (A-1) % 4 == 2:
    cnt2[0] = 1

for i in range(num):
    if cnt1[i] == cnt2[i]:
        c = '0' + c
    else:
        c = '1' + c
print(int(c, 2))

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

b = format(B, 'b')
num = len(b)

cnt1 = [0]*num
for i in range(1, num):
    if (B+1)%(2**(i+1)) <= 2**i:
        continue
    else:
        if (B+1)%2 == 1:
            cnt1[i] = 1
if B % 4 == 1 or B % 4 == 2:
    cnt[0] = 1

c = ''
if A == 0:
    for i in range(num):
        if cnt1[i] == 0:
            c = '0' + c
        else:
            c = '1' + c
    print(int(c, 2))
    exit()

cnt2 = [0]*num
for i in range(1, num):
    if A%(2**(i+1)) <= 2**i:
        continue
    else:
        if A%2 == 1:
            cnt2[i] = 1
if (A-1) % 4 == 1 or (A-1) % 4 == 2:
    cnt2[0] = 1

for i in range(num):
    if cnt1[i] == cnt2[i]:
        c = '0' + c
    else:
        c = '1' + c
print(int(c, 2))
Problem p03317 (python)

Fixed submission:
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ind = A.index(1)
print(math.ceil((ind + (N-ind-1))/(K-1)))

Buggy submission (verdict: Runtime Error):
実装無理
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ind = A.index(1)
if (ind%(K-1) + (N-ind-1)%(K-1)) <= K-1:
    print(math.floor(ind/(K-1)) + math.floor((N-ind-1)/(K-1))+1)
else:
    print(math.ceil(ind/(K-1)) + math.ceil((N-ind-1)/(K-1)))

Buggy submission (verdict: Runtime Error):
実装無理
import math
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ind = A.index(1)
if (ind%(K-1) + (N-ind-1)%(K-1))%(K-1) == 0:
    print(math.floor(ind/(K-1)) + math.floor((N-ind-1)/(K-1))+1)
else:
    print(math.ceil(ind/(K-1)) + math.ceil((N-ind-1)/(K-1)))
Problem p03774 (python)

Fixed submission:
N, M = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(N)]
C = [[int(i) for i in input().split()] for j in range(M)]

ls1 = []
for i in range(N):
    ls2 = []
    for j in range(M):
        ls2.append(abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]))
    a = min(ls2)
    ls1.append(ls2.index(a))
for i in ls1:
    print(i+1)

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().split().strip()]
A = [[int(i) for i in input().split().strip()] for j in range(N)]
C = [[int(i) for i in input().split().strip()] for j in range(M)]

ls1 = []
for i in range(N):
    ls2 = []
    for j in range(M):
        ls2.append(abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]))
    a = min(ls2)
    ls1.append(ls2.index(a))
for i in ls1:
    print(i)
Problem p03986 (python)

Fixed submission:
s = input()
cnt = 0
cnt_set = 0
for x in s:
    if x == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt_set += 1
            cnt -= 1
print(len(s)-2*cnt_set)

Buggy submission (verdict: Runtime Error):
s = input()
cnt = 0
cnt_set = 0
for x in S:
    if x == 'S':
        cnt += 1
    else:
        if cnt > 0:
            cnt_set += 1
            cnt -= 1
print(len(s)-2*cnt_set)
Problem p02623 (python)

Fixed submission:
import itertools
import bisect
N, M, K = map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))

ans = 0
l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
import bisect
N, M, K = map(int,input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 

A_ = list(itertools.accumulate(A))
B_ = list(itertools.accumulate(B))


l = len(A_)
ans = max(ans, bisect.bisect_right(B_, K))
for idx, i in enumerate(A_):
  if i <= K:
          ans = max(idx+1 + bisect.bisect_right(B_, K-i), ans)
  
print(ans)
Problem p02659 (python)

Fixed submission:
A, B = input().split()
B = B.replace('.', '')
A = int(A)
B = int(B)

print(int(A*B//100))

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
A, B = map(input().split())
B = B.replace('.', '')
A = int(A)
B = int(B)

print(int(A*B//100))
Problem p02726 (python)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N, X, Y = map(int,input().split())
l = [[0]*(N) for _ in range(N)]
for i in range(N-1):
    l[i][i+1] = 1
    l[i+1][i] = 1
l[X-1][Y-1] = 1
l[Y-1][X-1] = 1
csr = csr_matrix(l)
step = np.array(np.ravel(dijkstra(csr, unweighted=True)), dtype=int)
memo = np.bincount(step)//2
ma = np.max(step)
for i in range(1,ma+1):
    print(memo[i])
for i in range(ma+1, N):
    print(0)

Buggy submission (verdict: Runtime Error):
import networkx as nx
from collections import Counter
import itertools
#import numpy as np

N, X, Y = map(int,input().split())
G = nx.Graph()
Node = range(N)
G.add_nodes_from(Node)
Edge = []
for i in range(N-1):
    Edge.append((i,i+1))
G.add_edges_from(Edge)
G.add_edge(X-1, Y-1)
path = dict(nx.all_pairs_shortest_path_length(G))
length = []

#辞書から値を削除（同じ頂点には行かない）
for i in range(N):
    del path[i][i]
#値だけとりだす
for i in range(N):
    length.append(list(path[i].values()))
#一次元にしてカウント
step = list(itertools.chain.from_iterable(length))
count = Counter(step)
ma = max(step)
for i in range(1,ma+1):
    print(count[i]//2)
for i in range(ma+1, N):
    print(0)
Problem p02990 (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, K = map(int, input().split())

if N-K+1 > K:
    p = K
    for i in range(1, p+1):
        a = cmb(N-K+1, i) * cmb(K-1, i-1)
        print(int(a%1000000007))
else:
    p = N-K+1
    for i in range(1, p+1):
        a = cmb(N-K+1, i) * cmb(K-1, i-1)
        print(int(a%1000000007))
            
    for i in range(N-K+2, K+1):
        print(0)

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

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

if N-K+1 > K:
    p = K
    for i in range(1, p+1):
        a = factorial(N-K+1) / factorial(N-K+1-i) / factorial(i) * factorial(K-1) / factorial(K-i) / factorial(i-1)
        print(int(a%1000000007))
        
else:
    p = N-K+1
    for i in range(1, p+1):
        a = factorial(N-K+1) / factorial(N-K+1-i) / factorial(i) * factorial(K-1) / factorial(K-i) / factorial(i-1)
        print(int(a%1000000007))
    
    for i in range(N-K+2, K+1):
        print(0)
Problem p03013 (python)

Fixed submission:
import sys
n, m = map(int,input().split())
a = [int(input()) for i in range(m)]
b = [0] * (m+1)
ans = 1
step = [0] * (n+1)
step[0] = 1
step[1] = 1
for i in range(2, n+1):
    step[i] = (step[i-1] + step[i-2]) % 1000000007
if m == 0:
    print(step[n])
    sys.exit()
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        print("0")
        quit()
if m > 0:
    b[0] = a[0] - 1
    b[m] = n - a[-1] - 1   
if m >= 2:
    for i in range(m-1, 0, -1):
        b[i] = a[i] - a[i-1] - 2
for i in b:
    ans = ans * step[i] % 1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = [int(input()) for i in range(m)]
b = [0] * (m+1)
b[0] = a[0] - 1
b[m] = n - a[-1] - 1
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        print("0")
        quit()
if m >= 2:
    for i in range(m-1, 0, -1):
        b[i] = a[i] - a[i-1] - 2
ans = 1
step = [0] * (n+1)
step[0] = 1
step[1] = 1
for i in range(2, n+1):
    step[i] = (step[i-1] + step[i-2]) % 1000000007
for i in b:
    ans = ans * step[i] % 1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = [int(input()) for i in range(m)]
b = [0] * (m+1)
b[0] = a[0] - 1
b[m] = n - a[-1] - 1
if m >= 2:
    for i in range(m-1, 0, -1):
        b[i] = a[i] - a[i-1] - 2
for i in range(m-1):
    if a[i] + 1 == a[i+1]:
        print("0")
        quit()
ans = 1
step = [0] * (n+1)
step[0] = 1
step[1] = 1
for i in range(2, n+1):
    step[i] = (step[i-1] + step[i-2]) % 1000000007
for i in b:
    ans = ans * step[i] % 1000000007
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
a = [int(input()) for i in range(m)]
b = [0] * (m+1)
b[0] = a[0] - 1
b[m] = n - a[-1] - 1
if m >= 2:
    for i in range(m-1, 0, -1):
        b[i] = a[i] - a[i-1] - 1
if 0 in b:
    print("0")  
else:         
    ans = 1
    step = [0] * (n+1)
    step[0] = 1
    step[1] = 1
    for i in range(2, n+1):
        step[i] = step[i-1] + step[i-2]
    for i in b:
        ans = ans * step[i]
    print(ans)
Problem p02859 (python)

Fixed submission:
print(int(input())**2)

Buggy submission (verdict: Runtime Error):
print (int(input)**2)
Problem p03127 (python)

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

import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

print (gcd_list(A))

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

import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print (gcd_list(A))
Problem p02580 (python)

Fixed submission:
H, W, M = map(int, input().split())

hs = [0] * H
ws = [0] * W
checked = set()

for i in range(M):
    r,c = map(int, input().split())
    r -= 1
    c -= 1

    hs[r] += 1
    ws[c] += 1
    checked.add((r, c))

mh, mw = 0, 0
for i in range(H):
    mh = max(mh, hs[i])
for j in range(W):
    mw = max(mw, ws[j])

max_h_list = []
max_w_list = []
    
for i in range(H):
    if hs[i] == mh: max_h_list.append(i)    
for j in range(W):
    if ws[j] == mw: max_w_list.append(j)

ans = mh + mw

for i in max_h_list:
    for j in max_w_list:
        if (i,j) not in checked:
            print(ans)
            exit()
print(ans-1)

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

hs = [0] * H
ws = [0] * W
checked = set()

for i in range(M):
    r,c = map(int, input().split())
    r -= 1
    c -= 1

    hs[r] += 1
    ws[c] += 1
    checked.add((r, c))

mh, mw = 0, 0
for i in range(H):
    mh = max(mh, hs[i])
    mw = max(mw, ws[i])

max_h_list = []
max_w_list = []
    
for i in range(H):
    if hs[i] == mh: max_h_list.append(i)    
for i in range(W):
    if ws[i] == mw: max_w_list.append(i)

ans = mh + mw

for i in max_h_list:
    for j in max_w_list:
        if (i,j) not in checked:
            print(ans)
            exit()
print(ans-1)

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

hs = [0] * H
ws = [0] * W
checked = set()

for i in range(M):
    r,c = map(int, input().split())
    r -= 1
    c -= 1

    hs[r] += 1
    ws[c] += 1
    checked.add((r, c))

mh, mw = 0, 0
for i in range(H):
    mh = max(mh, hs[i])
    mw = max(mw, ws[i])

max_h_list = []
max_w_list = []
    
for i in range(H):
    if hs[i] == mh: max_h_list.append(i)    
for j in range(W):
    if ws[i] == mw: max_w_list.append(i)

ans = mh + mw

for i in max_h_list:
    for j in max_w_list:
        if (i,j) not in checked:
            print(ans)
            exit()
print(ans-1)
Problem p02820 (python)

Fixed submission:
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

ans = ""
score = 0

for i, t in enumerate(T):
    if t == 'r':
        if i >= K and "p" == ans[-K]:
            ans += " "
        else:
            ans += 'p'
            score += P    

    elif t == 's':
        if i >= K and "r" == ans[-K]:
            ans += " "
        else:
            ans += 'r'
            score += R 
    else:
        if i >= K and 's' == ans[-K]:
            ans += " "
        else:
            ans += 's'
            score += S
print(score)

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

N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

index = defaultdict(list)

for i, t in enumerate(T):
    index[t].append(i)


len_r = len(index['r'])
len_s = len(index['s'])
len_p = len(index['p'])

tmp = 0
flag = True
for i in index['r']:    
    if tmp % K == 0 and flag == True:
        len_r -= 1
        flag = False
        tmp = i
        continue
    if tmp % K == 0 and flag == False:    
        flag = True
        tmp = i
        continue
    tmp += i -tmp

tmp = 0
flag = True
for j in index['s']:    
    if tmp % K == 0 and flag == True:
        len_s -= 1
        flag = False
        tmp = js
        continue
    if tmp % K == 0 and flag == False:    
        flag = True
        tmp = j
        continue
    tmp += j - tmp

tmp = 0
flag = True
for k in index['p']:    
    if tmp % K == 0 and flag == True:
        len_p -= 1
        flag = False
        tmp = k
        continue
    if tmp % K == 0 and flag == False:    
        flag = True
        tmp = k
        continue
    tmp += k-tmp

ans = P * len_r + R * len_s + S * len_p
print(ans)
Problem p03137 (python)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

X = list(map(int, input().split()))

if N >= M:
    print(0)
    sys.exit()
X.sort()

dist = []
for i in range(len(X)-1):
    dist.append(X[i+1]-X[i])

dist.sort()
print(sum(dist[:len(dist)-(N-1)]))

Buggy submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

N, M = map(int, input().split())

X = list(map(int, input().split()))

X.sort()

if M == 1:
    print(0)
    sys.exit()

dist = []

for i in range(len(X)-1):
    dist.append(X[i+1] - X[i])

dist.sort(reverse=True)

ans = X[-1] - X[0]
for i in range(N-1):
    ans -= dist[i]
print(ans)
Problem p03209 (python)

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def rec(n,x):
    if n == 0:
        return 0 if x <= 0 else 1
    #真ん中以下まで到達    
    elif x <= 1 + a[n-1]:
        #バンズが一枚増えているので,真ん中以下までしか到達してない場合はn-1からx-1食べるのと同じ
        return rec(n-1, x-1)
    #真ん中以降まで到達
    else:
        #バンズ+N-1バーガー+真ん中のパティ+N-1バーガーのうち[x-a[n-1]-2]分を食べる

        return p[n-1] + 1 + rec(n-1, x-a[n-1]-2)

print(rec(N,X))

Buggy submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def rec(n,x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n-1]:
        return rec(n-1, x-1)
    elif x == 2 + a[n-1]:
        return p[n-1] + 1
    elif 2 + a[n-1] < x <= 2 + 2*a[n-1]:
        return rec(n-1, x-2-a[n-1]) + p[n-1] + 1
    elif 3 + a[n-1] == x:
        return 2*p[n-1] + 1

print(rec(N,X))
Problem p02729 (python)

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

def fac(n):
  if n == 0:
    return 1
  else:
    return n * fac(n-1)

def binom(n,k):
  if n==0 or n==1:
    return 0
  else:
    return fac(n) // (fac(n-k) * fac(k))

print(binom(n,2) + binom(m,2))

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

def fac(n):
  if n == 0:
    return 1
  else:
    return n * fac(n-1)

def binom(n,k):
  if n==0:
    return 0
  else:
    return fac(n) // (fac(n-k) * fac(k))

print(binom(n,2) + binom(m,2))
Problem p02771 (python)

Fixed submission:
a,b,c=map(int,input().split())

if a==b and b==c: print('No')
elif a==b or b==c or c==a: print('Yes')
else: print('No')

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[input() for i in range(n)]
d={}
for i in range(n):
  d[s[i]] = d.get(s[i],0) + 1

max_k_list = [kv[0] for kv in d.items() if kv[1] == max(d.values())]
max_k_list.sort()
print(*max_k_list)
Problem p02792 (python)

Fixed submission:
n=int(input())
cnt=[[0]*10 for i in range(10)] #(10,10)サイズの配列
ret = 0

def hoge(m):
    #return m[-1],m[0]
    return (m%10, int(str(m)[0]))

for k in range(1,n+1):
    a,b = hoge(k)
    cnt[a][b] += 1    

for i in range(1,10):
    for j in range(1,10):
        ret += cnt[i][j] * cnt[j][i]

print(ret)

Buggy submission (verdict: Runtime Error):
cnt_1 = 0
cnt_2 = 0
for i in range(1,n+1):
    for j in range(i,n+1):
        #対象な場合
        #(1,1),(22,22),(333,333)
        if i==j and (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):
            cnt_1 += 1
        #異なる数字の場合
        #揃っていてもnより大きい場合はNG
        elif (str(i)[0]==str(j)[-1] and str(i)[-1]==str(j)[0]):
                cnt_2 += 1
print(cnt_1 + cnt_2*2)
Problem p02831 (python)

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

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
  
print(lcm(a,b))

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

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
  
print(lcm(a,b))
Problem p02862 (python)

Fixed submission:
def cmb(n, r, p):
    if r<0 or n<r:
        return 0
    r=min(r, n-r)
    return fact[n]*factinv[r]*factinv[n-r]%p

mod=10**9+7
MAXN=2*10**6+10
fact=[1, 1]
factinv=[1, 1]
inv=[0, 1]

for i in range(2, MAXN+1):
    fact.append((fact[-1]*i)%mod)
    inv.append(-inv[mod%i]*(mod//i)%mod)
    factinv.append((factinv[-1]*inv[-1])%mod)

x,y=map(int, input().split())
res=0
if (x+y)%3==0:
    m=(2*x-y)//3
    n=(2*y-x)//3
    res=cmb(m+n,m,mod)
print(res)

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())

if (x+y)%3!=0:print(0)
else:
    n,m=y//3,y//3
    p = 10**9+7
    N = 2*10**6+10  # N は必要分だけ用意する
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用
    for i in range(2, N+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    print(cmb(n+m,n,p))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())

if (x+y)%3!=0:print(0)
else:
    n,m=y//3,y//3
    p = 10**9+7
    N = 2+10**6+10  # N は必要分だけ用意する
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用
    for i in range(2, N+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    print(cmb(n+m,n,p))

Buggy submission (verdict: Runtime Error):
x,y=map(int,input().split())

if (x+y)%3!=0: print(0)
else:
    n,m=y//3,y//3
    p = 10 ** 9 + 7
    N = 10 ** 6  # N は必要分だけ用意する
    fact = [1, 1]  # fact[n] = (n! mod p)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
    inv = [0, 1]  # factinv 計算用
    for i in range(2, N+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)
    print(cmb(n+m,n,mod))
Problem p02873 (python)

Fixed submission:
s = input()
n = len(s)
res = [0] * (n + 1)
t = 0
for i in range(n):
	if s[i] == '<':
		t += 1
	else:
		t = 0
	res[i + 1] = t

t = 0
for i in range(n - 1, -1, -1):
	if s[i] == '>':
		t += 1
	else:
		t = 0
	res[i] = max(res[i], t)

print(sum(res))

Buggy submission (verdict: Runtime Error):
s = input()

def rle(s):
	tmp, count, ans = s[0], 1, ""
	for i in range(1,len(s)):
		if tmp == s[i]:
			count += 1
		else:
			ans += tmp + str(count)
			tmp = s[i]
			count = 1
	ans += tmp + str(count)
	return ans

r = rle(s)

if (len(r) // 2) % 2 == 1:
	r += '>0'

res = 0
for i in range(len(r) // 4):
	a, b = int(r[4*i+1]), int(r[4*i+3])
	ma, mi = max(a, b), min(a, b)
	res += (ma * (ma + 1)) // 2 + (mi * (mi - 1)) // 2
print(res)
Problem p02880 (python)

Fixed submission:
n = int(input())

lis = []
for i in range(10):
  for j in range(i,10):
    lis.append(i*j)
    
if n in lis: print('Yes')
else: print('No')

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

qq = []
for i in range(1,10):
  for j in range(1,10):
    qq.append(i*j) if i*j not in qq

print('Yes') if n in qq else print('No')
Problem p02881 (python)

Fixed submission:
n=int(input())
mini=2*n
for a in range(1,int(n**0.5)+1):
    if n%a==0:
        b=n//a
        if mini>a+b:
            mini=a+b
print(mini-2)

Buggy submission (verdict: Runtime Error):
n=int(input())
#n=i*jを満たすi,jで，i+jが最小

lis=prime_factorize(n)
lis.sort()
lis_a=[lis[i] for i in range(len(lis)) if i%2==0]
lis_b=[lis[i] for i in range(len(lis)) if i%2!=0]
print(product(lis_a)+product(lis_b)-2)

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 product(lis):
    res=1
    for i in range(len(lis)):
        res*=lis[i]
    return res
Problem p03038 (python)

Fixed submission:
n, m = map(int, input().split())
a = [(1, int(i)) for i in input().split()]
for _ in range(m):
    b, c = map(int, input().split())
    a.append((b, c))
a = sorted(a, key=lambda x: x[1])
res = 0
idx = 0
while idx < n:
    b, c = a.pop()
    p = min(b, n-idx)
    res += p * c
    idx += p
print(res)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [(1, int(i)) for i in input().split()]
for _ in range(m):
    b, c = map(int, input().split())
    a.append((b, c))
a = sorted(a, key=lambda x: x[1])
res = 0
idx = 0
while idx < n:
    b, c = a.pop()
    p = min(b, n-t)
    res += p * c
    idx += p
print(res)