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

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

if A>=1 and A<=9 and B>=1 and B<=9:
  print(A*B)
else:
  print(-1)

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

if A=>1 and A<=9 and B=>1 and B<=9:
  print(A*B)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
#ABC144_C
#素因数分解して、N＝なるべく差の小さい2つの因数の積、と考える
import math

init_N=int(input())
N=init_N
ans_list=[]
A=1
B=1

for i in range(2,int(math.sqrt(init_N))+1):
    while 1:  
        if N%i==0:
            ans_list.append(i)
            N=N//i
        else:
            break
if N==1:
    pass
else:
    ans_list.append(N)

if len(ans_list)==1:
    print(str(init_N-1))
else:
    while len(ans_list)>0:
        A=A*ans_list.pop(0)
        #print(A)
        if len(ans_list)!=0:
            B=B*ans_list.pop(0)
            #print(B)
    print(str(A+B-2))

Buggy submission (verdict: Runtime Error):
#ABC144_C
#素因数分解して、N＝なるべく差の小さい2つの因数の積、と考える
import math

init_N=int(input())
N=init_N
ans_list=[]
A=1
B=1

for i in range(2,int(math.sqrt(init_N))+1):
    while 1:  
        if N%i==0:
            ans_list.append(i)
            N=N//i
        else:
            break
if N==1:
    pass
else:
    ans_list.append(N)

if len(ans_list)==1:
    print(str(init_N-1))
else:
    while len(ans_list)>0:
        A=A*ans_list.pop(0)
        print(A)
        if len(ans_list)!=0:
            B=B*ans_list.pop(0)
            print(B)
    print(str(A+B-2))
Problem p02881 (python)

Fixed submission:
import math

n=int(input())
n2=int(math.sqrt(n))

minimum=n-1
for i in range(1,n2+1):
    if(n%i==0):
        minimum=min(minimum,(n//i-1)+(i-1))

print(minimum)

Buggy submission (verdict: Runtime Error):
#ABC144_C
#素因数分解して、N＝なるべく差の小さい2つの因数の積、と考える
import math

init_N=int(input())
N=init_N
ans_list=[]
A=1
B=1

for i in range(2,int(math.sqrt(init_N))+1):
    while 1:  
        cnt+=1
        if N%i==0:
            ans_list.append(i)
            N=N//i
        else:
            break
if N==1:
    pass
else:
    ans_list.append(N)

if len(ans_list)==1:
    print(str(init_N-1))
else:
    while len(ans_list)>0:
        A=A*ans_list.pop(0)
        print(A)
        if len(ans_list)!=0:
            B=B*ans_list.pop(0)
            print(B)
    print(str(A+B-2))
Problem p03073 (python)

Fixed submission:
#124_C

S=input()

a=''
b=''

lenS=len(S)

for i in range(lenS):
    if i%2==0:
        a+='1'
        b+='0'
    else:
        a+='0'
        b+='1'
        
ca=0
cb=0
for i in range(lenS):
    if a[i]!=S[i]:
        ca+=1
    if b[i]!=S[i]:
        cb+=1
print(min(ca,cb))

Buggy submission (verdict: Runtime Error):
#ABC124_C
S=input()
 
S_rev=list(S)[::-1]
 
s=0
st0=0
st1=0
 
def bit_count(x):
    x=bin(x)[2:]
    ans=0
    for i in range(len(x)):
        if int(x[i])==1:
            ans+=1
    return ans
            
 
for i in range(len(S)):
    if i%2==0:
        st0+=2**i
    else:
        st1+=2**i
    if int(S_rev[i])==1:
        s+=2**i
 
cand0=st0^s
cand1=st1^s
 
    
bc0=bit_count(cand0)
bc1=bit_count(cand1)
if bc0>bc1:
    print(bc1)
else:
    print(bc0
Problem p03127 (python)

Fixed submission:
#ABC118_C
from fractions import gcd
from functools import reduce

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

ans=reduce(gcd,A)
print(ans)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce

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

print(reduce(gcd,A))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce

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

print(reduce(gcd,A))
Problem p03208 (python)

Fixed submission:
N,K=map(int,input().split())
H=[int(input()) for _ in range(N)]
H.sort(reverse=True)
ans=10**9

for i in range(N-K+1):
    ans=min(ans,H[i]-H[i+K-1])

print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
H=list(map(int,input().split()))
H.sort()
ans=10**6

for i in range(N-K):
    ans=min(ans,H[i]-H[i+K])

print(ans)
Problem p03252 (python)

Fixed submission:
from collections import Counter

S=input()
T=input()

S=list(Counter(S).values())
T=list(Counter(T).values())

S.sort()
T.sort()

if S==T:
  print('Yes')
else:
    print('No')

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

S=input()
T=input()

S=Counter(S).values()
T=Counter(T).values()

S.sort()
T.sort()

if S==T:
    print('Yes')
else:
    print('No')
Problem p03317 (python)

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

ans=1
X=N-K

while X>0:
  X-=K-1
  ans+=1
print(ans)

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

ans=1
X=N-K

while X>0:
  X-=K-1
  ans+=1
print(ans)
Problem p02570 (python)

Fixed submission:
D,T,S = [int(x) for x in input().split()]

if T*S >= D:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
D,T,S = int(input().split())

if T*S >= D:
    print("Yes")
else:
    print("No")
Problem p02754 (python)

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

if N == 0:
  print(0)
  exit()

cnt = N // (A + B)
rem = N % (A + B)

ans = 0

if rem >= A:
  ans = A * (cnt + 1)
else:
  ans = A * cnt + rem

print(ans)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
ball = ''
cnt = 0

while N > 0:
  if cnt % 2 == 0:	# 青
    i = min(A, N)
    ball = ball + 'b' * i
  else:				# 赤
    i = min(B, N)
    ball = ball + 'r' * i
  N -= i
  cnt += 1

print(ball.count('b'))
Problem p02707 (python)

Fixed submission:
#!/usr/bin/env python3
from sys import stdin


def solve(tc):
    n = int(stdin.readline().strip())
    ai = list(map(int, stdin.readline().split()))

    adj = [[] for i in range(n)]
    for i in range(n - 1):
        adj[ai[i] - 1].append(i + 1)

    for children in adj:
        print(len(children))



LOCAL_TEST = not __debug__
if LOCAL_TEST:
    infile = __file__.split('.')[0] + "-test.in"
    stdin = open(infile, 'r')

tcs = 1
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
from sys import stdin


def solve(tc):
    n = int(stdin.readline().strip())
    ai = list(map(int, stdin.readline().split()))

    adj = [[] for i in range(n)]
    for i in range(n - 1):
        adj[ai[i] - 1].append(i + 1)

    for children in adj:
        print(len(children))



LOCAL_TEST = not __debug__
if LOCAL_TEST:
    infile = __file__.split('.')[0] + "-test.in"
    stdin = open(infile, 'r')

tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1
Problem p02835 (python)

Fixed submission:
#!/usr/bin/env python3
import sys

a1, a2, a3 = map(int, sys.stdin.readline().split())
if a1+a2+a3>=22:
  print('bust')
else:
  print('win')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

a1, a2, a3 = map(int, sys.stdin.readline().split())
if a1+a2+a3>=22:
  print('bust')
  return
print('win')

Buggy submission (verdict: Runtime Error):
a1, a2, a3 = map(int, stdin.readline().split())
if a1+a2+a3>=22:
  print('bust')
  return
print('win')

Buggy submission (verdict: Runtime Error):
from sys import stdin

a1, a2, a3 = map(int, stdin.readline().split())
if a1+a2+a3>=22:
  print('bust')
  return
print('win')
Problem p02836 (python)

Fixed submission:
#!/usr/bin/env python3
from sys import stdin

s = stdin.readline().strip()
sl = len(s)

cnt = 0
for i in range(sl//2):
  if s[i]!=s[sl-1-i]:
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

s = stdin.readline().strip()
sl = len(s)

cnt = 0
for i in range(sl//2):
  if s[i]!=s[sl-1-i]:
    cnt += 1

print(cnt)

Buggy submission (verdict: Runtime Error):
import sys.stdin

s = stdin.readline().strip()
sl = len(s)

cnt = 0
for i in range(sl//2):
  if s[i]!=s[sl-1-i]:
    cnt += 1

print(cnt)
Problem p02729 (python)

Fixed submission:
N, M = map(int, input().split())
print(int((N!=0) * N * (N-1)/2 + (M!=0) * M *(M-1)/2))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A_set = list(set(A))
Ad = {a_set: A.count(a_set) for a_set in A_set}
score_sum = sum([(x>1) * x * (x-1) / 2 for x in list(Ad.values())])
Ad_score = {ad_key: score_sum - (ad_value -1) * (ad_value > 0) for ad_key, ad_value in Ad.items()}
A_out = [str(int(Ad_score[a])) for a in A]

print('\n'.join(A_out))
Problem p02711 (python)

Fixed submission:
N = input()
if '7' in N:
    print('Yes')
else:
    print('No')

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

DP = [[-10**9 for i in range((N+1)//2)] for i in range(N)]

DP[0][0] = A[0]
for i in range(1,N):
    DP[i][0] = max(DP[i-1][0],A[i])

for i in range(1,N//2-1):
    DP[2*i][i] = DP[2*(i-1)][i-1] + A[2*i]

for i in range(3,N):
    for j in range(i//2-1,(i+1)//2):
        DP[i][j] = max(DP[i-1][j],DP[i-2][j-1]+A[i])

print(DP[N-1][N//2-1])
Problem p02723 (python)

Fixed submission:
S = input()

if S[2]==S[3] and S[4]==S[5]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N,X,Y = map(int,input().split())

k = defaultdict(lambda: 0)

for i in range(N-1):
    for j in range(i+1,N):
        dist = min( j-i , abs(X-1-i)+1+abs(Y-1-j) , abs(Y-1-i)+1+abs(X-1-j) )
        k[dist] += 1

for i in range(1,N+1):
    print(k[i])
Problem p02688 (python)

Fixed submission:
#!/usr/bin/env python3
import sys

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()

    N = int(next(tokens))  # type: str
    K = int(next(tokens))  # type: str
    # print(N, K)
    g = set()
    for _ in range(K):
        d = int(next(tokens))
        g = g | set([int(next(tokens)) for i in range(d)])

    print(N - len(g))    

    return


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: str
    K = (next(tokens))  # type: str
    g = set()
    for _ in range(N):
        d = int(next(tokens))
        g = g  or set([int(next(tokens)) for i in range(d)])

    print(N - len(g))    

    return


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

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(N: int, A: int, B: int):

    if N <= A : print(N)    
    else :
        k = N // (A+B)
        rem = N - (A+B)*k
        if  rem >= A:
            print(k*A+A)
        elif rem >= 0:
            print(k*A+rem)
        else : print(k*A)


    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
 
 
def solve(N: int, A: int, B: int):
 
    # if A+B < N : N = A+B
    if N <= A : print(N)
    else : 
        k = N // (A+B)
        rem = N - (A+B)*k
        b_ = A - rem
        if  b_ >= 0: print(k*A+rem+1)
        else : print(k*A)
 
 
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)
 
if __name__ ==
Problem p02862 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
MOD = 1000000007  # type: int

def combination(n: int, r:int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def solve(X: int, Y: int):

    u = (2*Y - X)//3
    r = (X- u)//2

    if ((2*Y - X)%3!=0) or (r*u <0):
        print(0)
        return

    a = combination(u+r, u)
    print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from math import factorial

MOD = 1000000007  # type: int
from numba import jit

# @jit
def combination(n: int, r:int, mod=MOD):
    n1 = n+1
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

def solve(X: int, Y: int):

    u = (2*Y - X)//3
    r = (X- u)//2

    if ((2*Y - X)%3!=0) or (r*u <0):
        print(0)
        return

    a = combination(u+r, u)
    print(a)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

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

Fixed submission:
n=int(input())
if n%9==0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n=int(input())
if n%9==o:
  print('Yes')
else:
  print('No')
Problem p02578 (python)

Fixed submission:
n=int(input())

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
    else:
      b.append(0)
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)

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

a=list(map(int,input().split()))
  
b=[]
if n>1:
  for j in range (n-1):
    c=a[j]-a[j+1]
    if c>-1:
      b.append(c)
      a[j+1]=a[j+1]+c
      
   
  if max(b)>-1:
    print(sum(b))
  else:
    print(0)
    
else:
  print(0)

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

a=list(map(int,input().split()))
  
b=[]
for j in range (n-1):
  c=a[j+1]-a[j]
  b.append(c)

if max(b)>-1:
  print(max(b))
else:
  print(0)

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

a=list(map(int,input().split()))
  
b=[]
for j in range (n-1):
  c=a[j+1]-a[j]
  b.append(c)
  
print(max(b))
Problem p02598 (python)

Fixed submission:
import math
N, K = map(int, input().split())

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

def cal(x):
    s = 0
    for aa in a:
        s += math.ceil(aa / x) - 1
    if s <= K: return True
    else: return False

l = 0
r = max(a)
while abs(r - l) > 1:
    mid = (l + r) // 2
    if cal(mid):
        r = mid
    else:
        l = mid
print(r)

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

a = list(map(int, input().split()))
a.sort(reverse=True)
lst = []
for i in a:
    lst.append([-i, 0])

heapq.heapify(lst)

i = 0
while i < K:
    p1 = heapq.heappop(lst)
    p2 = heapq.heappop(lst)
    k = int(p1[0]*p1[1]/p2[0] - p1[1] + 1)
    if i + k <= K:
        p1[0] = p1[0] * (p1[1] + 1) / (p1[1] + 1 + k)
        p1[1] += k
        i += k
    else:
        p1[0] = p1[0] * (p1[1] + 1) / (p1[1] + 1 + K - i)
        p1[1] += K - i
        i = K
        
    heapq.heappush(lst, p1)
    heapq.heappush(lst, p2)

p = heapq.heappop(lst)
print(math.ceil(-p[0]))
Problem p02735 (python)

Fixed submission:
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
s = [input().rstrip() for _ in range(H)]

dp = [[1000]*W for _ in range(H)]

if s[0][0] == '#': dp[0][0] = 1
else: dp[0][0] = 0

for j in range(W):
    for i in range(H):
        if i <= H - 2:

            if s[i][j] == '.' and s[i+1][j] == '#':
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1)
            else: dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        if j <= W - 2:

            if s[i][j] == '.' and s[i][j+1] == '#':
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1)
            else: dp[i][j+1] = min(dp[i][j+1], dp[i][j])


print(dp[H-1][W-1])

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

H, W = map(int, input().split())
s = ['0' * (W+2)]
for _ in range(H):
    s.append('0' + input().rstrip() + '0')
s.append('0' * (W+2))

ans = []
if s[1][1] == '#': a = 1
else: a = 0
temp = [[1, 1, a]]

while temp:
    p = temp.pop()
    for y, x in [[p[0]+1, p[1]], [p[0], p[1]+1]]:
        if s[y][x] == '0':continue
        if s[y][x] == '#' and s[p[0]][p[1]] == '.':
            d = p[2] + 1
        if y == H and x == W:
            ans.append(d)
        else:
            temp.append([y, x, d])
            
print(min(ans))
Problem p02781 (python)

Fixed submission:
import math
n = int(input())
K = int(input())

def calk1(n):
    if n == 0: return 0
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))

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

def calk1(n):
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
if n < 10 ** (K - 1): print(0)
else:
    if K == 1: print(calk1(n))
    elif K == 2: print(calk2(n))
    else: print(calk3(n))

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

def calk1(n):
    m = int(math.log10(n))
    num = m * 9
    num += n//(10**m)
    return num

def calk2(n):
    m = int(math.log10(n))
    num = m * (m - 1) // 2 * 9**2
    num += (n//(10**m)-1) * m * 9
    num += calk1(n - (n//(10**m)*10**m))
    return num

def calk3(n):
    m = int(math.log10(n))
    num = m * (m - 1) * (m - 2) // 6 * 9**3
    num += (n//(10**m)-1) * (m * (m - 1) // 2 * 9**2)
    num += calk2(n - (n//(10**m)*10**m))
    return num
    
if K == 1: print(calk1(n))
elif K == 2: print(calk2(n))
else: print(calk3(n))
Problem p02833 (python)

Fixed submission:
import math
N = int(input())

ans = 0

if N%2==1:ans=0
else:
    for i in range(int(math.log(N+1,5))):
        ans += N//(5**(i+1)*2)
print(ans)

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

ans = 101

if N%2==1:ans=0
else:
    for i in range(int(math.log(N,5))):
        ans += N//(5**(i+1)*2)
print(ans)

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

ans = 0

for i in range(int(math.log(N,5))):
    ans += N//(5**(i+1)*2)
print(ans)
Problem p02862 (python)

Fixed submission:
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
X, Y = map(int,input().split())

mm = (2*Y - X) / 3
nn = (2*X - Y) / 3

ans = 0

if mm.is_integer() and nn.is_integer():
    mm = int(mm)
    nn = int(nn)
    if mm >=0 and nn>=0:
        ans =comb(mm+nn, nn, 10**9+7)
      
print(ans)

Buggy submission (verdict: Runtime Error):
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
X, Y = map(int,input().split())

m = (2*Y - X) / 3
n = (2*X - Y) / 3

ans = 0

if m.is_integer() and n.is_integer():
    m = int(m)
    n = int(n)
    if m<n:m, n = n, m
        
print(comb(m+n, n, 10**9+7))
Problem p02873 (python)

Fixed submission:
S = input()

lst = [1 if S[0]=='<' else -1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        if S[i]=='<':lst[-1] += 1
        else: lst[-1] -= 1
    else:
        if S[i]=='>':lst.append(-1)
        else: lst.append(1)
ans = [0]

for i in range(len(lst)):
    if lst[i] > 0:
        for j in range(0, lst[i] + 1):
            ans.append(j)
    else:
        ans[-1] = max(ans[-1], -lst[i])
        for j in range(0, -lst[i]):
            ans.append(-lst[i]-j-1)

print(sum(ans))

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

s = S.replace('<>', '<,>').replace('><', '>,<').split(',')
lst1 = [ss.count('<') - ss.count('>') for ss in s]

ans = [0]

for i in lst:
    if i > 0:
        ans += list(range(1,i+1))
    else:
        ans[-1] = max(ans[-1], -i)
        ans += list(range(-i-1,-1, -1))

print(sum(ans))

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

lst = [1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        if S[i]=='<':lst[-1] += 1
        else: lst[-1] -= 1
    else:
        if S[i]=='>':lst.append(-1)
        else: lst.append(1)

ans = []
con = 0

for i in range(len(lst)):
    if lst[i] > 0:
        for j in range(0, lst[i] + 1):
            ans.append(j)
        con = lst[i]
    else:
        ans[-1] = max(con, -lst[i])
        for j in range(0, -lst[i]):
            ans.append(-lst[i]-j-1)
        cont = 0
print(sum(ans))
Problem p02912 (python)

Fixed submission:
import heapq

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

a = [-int(x) for x in input().split()]

heapq.heapify(a)

num = 0
hq = 1

while num < M and hq != 0:
    hq = -heapq.heappop(a)
    hq2 = hq // 2
    heapq.heappush(a, -hq2)
    num += 1

print(-sum(a))

Buggy submission (verdict: Runtime Error):
import sys
input= sys.stdin.readline
N, M = map(int,input().split())
 
A= list(map(int,input().split()))
 
A.sort(reverse=True)
cnt = 1
A[0]=A[0]//2
 
if N==1:
    while A[0]>0 and cnt<M:
        cnt+=1
        A[0]=A[0]//2
else:
    while cnt<M:
        c=min(M-cnt,int(math.log2(A[0]/A[1])+1))
        cnt+=c
        A[0]=A[0]//(2**c)
          
        b=A[0]
        A.sort(reverse=True)
    
print(sum(A))