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

Fixed submission:
size = 500001
mod = 10 ** 9 + 7
fac = [0] * size
finv = [0] * size
inv = [0] * size

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, size):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod

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

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, size + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def nCr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

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

ans = 0
flag = 1

for k in range(N+1):
    ans += flag * nPr(M - k, N - k, mod) * nCr(N, k, mod) * nPr(M, N, mod)
    flag *= -1
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
size = 500000
mod = 10 ** 9 + 7
fac = [0] * size
finv = [0] * size
inv = [0] * size

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, size):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod

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

g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, size + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def nCr(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

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

ans = 0
flag = 1

for k in range(N+1):
    ans += flag * nPr(M - k, N - k, mod) * nCr(N, k, mod) * nPr(M, N, mod)
    flag *= -1
    ans %= mod

print(ans)
Problem p02659 (python)

Fixed submission:
A, B = input().split()
A = int(A)
C, D = B.split('.')
B = 100 * int(C) + int(D)
ans = A * B // 100
print(ans)

Buggy submission (verdict: Runtime Error):
A, B = map(int,input().split())
ans = int(A*B)
print(ans)
Problem p02695 (python)

Fixed submission:
N, M, Q = map(int,input().split())
L = []
def dfs(List):
    if len(List) == N - 1:
        L.append([0] + List)
    else:
        k = List[-1]
        for i in range(M-k):
            n_L = List[:]
            n_L.append(k+i)
            dfs(n_L)
for i in range(M):
    dfs([i])

Qs = []
for _ in range(Q):
    Qs.append(list(map(int,input().split())))

MAX = 0
for l in L:
    cnt = 0
    for a, b, c, d in Qs:
        if l[b-1] - l[a-1] == c:
            cnt += d
    MAX = max(cnt, MAX)
print(MAX)

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int,input().split())
L = []
def dfs(List):
    if len(List) == N - 1:
        L.append([0] + List)
    else:
        k = List[-1]
        for i in range(M-k):
            n_L = List[:]
            n_L.append(k+i)
            dfs(n_L)
for i in range(M):
    dfs([i])

MAX = 0
for l in L:
    cnt = 0
    for _ in range(Q):
        a, b, c, d = map(int,input().split())
        if l[b-1] - l[a-1] == c:
            cnt += d
    MAX = max(cnt, MAX)
print(MAX)

Buggy submission (verdict: Runtime Error):
N, M, Q = map(int,input().split())
L = []
def dfs(List):
    if len(List) == N - 1:
        L.append([0] + List)
    else:
        k = List[-1]
        for i in range(M-k):
            n_L = List[:]
            n_L.append(k+i)
            dfs(n_L)
for i in range(M):
    dfs([i])

MAX = 0
for l in L:
    cnt = 0
    for _ in range(Q):
        a, b, c, d = map(int,input().split())
        if l[b-1] - l[a-1] == c:
            cnt += d
    MAX = max(cnt, MAX)
print(MAX)
Problem p02793 (python)

Fixed submission:
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

LCM = lcm_list(A)
ans = 0

for i in range(N):
    ans+=LCM//A[i]
print(ans%mod)

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

def lcm_base(x, y):
    return (x * y) // fraction.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

LCM = lcm_list(A)
ans = 0

for i in range(N):
    ans+=LCM//A[i]
print(ans%mod)

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

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)#fraction

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7

LCM = lcm_list(A)
ans = 0

for i in range(N):
    ans+=LCM//A[i]
print(ans%mod)
Problem p02831 (python)

Fixed submission:
A,B = map(int,input().split())
def GCD(p,q):
    if p<q:
        p,q = q,p
    r = p
    p = q
    q = r%q
    if q!=0:
        return GCD(p,q)
    else:
        return p
gcd = GCD(A,B)
ans = (A*B)//gcd
print(ans)

Buggy submission (verdict: Runtime Error):
A,B = map(int,input().split())
GCD(p,q):
    if p<q:
        p,q = q,p
    p = q
    q = p%q
    if q!=0:
        GCD(p,q)
    else:
        return p
gcd = GCD(A,B)
ans = (A*B)//gcd
print(ans)
Problem p02836 (python)

Fixed submission:
S = list(input())
A = list(reversed(S))
LEN=len(S)
ans=0
if LEN%2==0:
    for i in range(LEN//2):
        if S[i]!=A[i]:
            ans+=1
else:
    for i in range((LEN-1)//2):
        if S[i]!=A[i]:
            ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
S = list(input())
A = reversed(S)
LEN=len(S)
ans=0
if LEN%2==0:
    for i in range(LEN//2):
        if S[i]!=A[i]:
            ans+=1
else:
    for i in range((LEN-1)//2):
        if S[i]!=A[i]:
            ans+=1
print(ans)
Problem p02912 (python)

Fixed submission:
import heapq

N, M = map(int,input().split())
A = list(map(lambda x: int(x) * (-1),input().split()))
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A)
    tmp *= -1
    tmp //= 2
    tmp *= -1
    heapq.heappush(A,tmp)
print(sum(A) * -1)

Buggy submission (verdict: Runtime Error):
import heapq

N, M = map(int,input().split())
A = list(map(lambda x: int(x) * (-1),input().split()))
heapq.heapify(A)
for i in range(M):
    tmp = heapq.heappop(A)
    tmp *= -1
    tmp //= 2
    tmp *= -1
    print(A)
print(sum(A) * -1)
Problem p02948 (python)

Fixed submission:
import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    try:
        L[A-1].append(-B)
    except:
        pass
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    try:
        ans -= heapq.heappop(Q)
    except:
        pass
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    L[A-1].append(-B)
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    try:
        ans -= heapq.heappop(Q)
    except:
        pass
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    L[A-1].append(-B)
Q = []
ans = 0
for i in range(M):
    for j in L[i]:
        heapq.heappush(Q, j)
    ans -= heapq.heappop(Q)
    
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
N, M = map(int,input().split())
L = [[] for _ in range(M)]
for _ in range(N):
    A, B = map(int,input().split())
    L[A-1].append(B)
Q = []
ans = 0
for i in range(M):
    Q += L[i]
    try:
        ans += heapq.heappop(Q)
    except:
        pass
print(ans)
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(4100000)

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

Q, K = map(int,input().split())
d = [INF] * N
d[K-1] = 0

def dfs(x):
    for u, cost in edges[x]:
        if d[u] == INF:
            d[u] = d[x] + cost
            dfs(u)

dfs(K-1)

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

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

Q, K = map(int,input().split())
d = [INF] * N
d[K-1] = 0

def dfs(x):
    for u, cost in edges[x]:
        if d[u] == INF:
            d[u] = d[x] + cost
            dfs(u)

dfs(K-1)

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

Fixed submission:
AB = input().split()
A = int(AB[0])
B = AB[1].split('.')
B = int(B[0])*100 + int(B[1])
print(A*B//100)

Buggy submission (verdict: Runtime Error):
AB = input().split()
A = int(AB[0])
B = int(AB[1]*100)
print(A*B//100)
Problem p02873 (python)

Fixed submission:
S = input()
sep = [0]
i=0
for i in range(len(S)-1):
    if S[i]=='<' and S[i+1]=='>': sep.append(i+1)
sep.append(i+2)

S += 'X'
ans = 0
center = 0
for i in range(len(sep)-1):
    s = S[sep[i]: sep[i+1]]
    l_max = s.count('>')
    ans += max(center, l_max)
    ans += l_max*(l_max-1)//2

    r_max = s.count('<')
    ans += r_max*(r_max-1)//2
    center = r_max

ans += center
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
sep = [0]
for i in range(len(S)-1):
    if S[i]=='<' and S[i+1]=='>': sep.append(i+1)
sep.append(i+2)

S += 'X'
ans = 0
center = 0
for i in range(len(sep)-1):
    s = S[sep[i]: sep[i+1]]
    l_max = s.count('>')
    ans += max(center, l_max)
    ans += l_max*(l_max-1)//2
    r_max = s.count('<')
    ans += r_max*(r_max-1)//2
    center = r_max

ans += center
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
sep = [0]
for i in range(len(S)-1):
    if S[i]=='<' and S[i+1]=='>': sep.append(i+1)
sep.append(i+2)

ans = 0
center = 0
for i in range(len(sep)-1):
    s = S[sep[i]: sep[i+1]]
    l_max = s.count('>')
    ans += max(center, l_max)
    ans += l_max*(l_max-1)//2

    r_max = s.count('<')
    ans += r_max*(r_max-1)//2
    center = r_max

ans += center
print(ans)
Problem p03272 (python)

Fixed submission:
N, i = map(int, input().split())
print(N-i+1)

Buggy submission (verdict: Runtime Error):
N, i = map(int, input())
print(N-i+1)
Problem p03634 (python)

Fixed submission:
N = int(input())

tree = {}

for _ in range(N-1):
  A, B, C = [int(i) for i in input().split()]
  if A not in tree:
    tree[A] = []
  if B not in tree:
    tree[B] = []
  tree[A].append((B, C))
  tree[B].append((A, C))


c = {}
q = []
visited = set()

def dfs(a, acc):
  q.append((a, acc))

  while q:
    n, r = q.pop()
    c[n] = r
    visited.add(n)
    for b, cost in ((b, cost) for b, cost in tree[n] if b not in visited):
      q.append((b, cost + r))


Q, K = [int(i) for i in input().split()]
dfs(K, 0)

for _ in range(Q):
  x, y = [int(i) for i in input().split()]
  print(c[x] + c[y])

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

tree = {}

for _ in range(N-1):
  A, B, C = [int(i) for i in input().split()]
  if A not in tree:
    tree[A] = []
  if B not in tree:
    tree[B] = []
  tree[A].append((B, C))
  tree[B].append((A, C))


c = {}
q = []
visited = set()

def dfs(a, acc):
  c[a] = acc
  for n, cost in tree[a]:
    if n not in visited:
      visited.add(n)
      dfs(n, acc + cost)


Q, K = [int(i) for i in input().split()]
visited.add(K)
c[K] = 0
dfs(K, 0)

for _ in range(Q):
  x, y = [int(i) for i in input().split()]
  print(c[x] + c[y])
Problem p02580 (python)

Fixed submission:
from collections import deque
h, w, m = map(int, input().split())
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=deque([])
dic = {}
mwi=deque([])
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]
 
for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    dic[a] = {}
    dic[a][b]=1
  else:
    dic[a][b]=1
 
  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)
 
  #ans[a][b]+=1

for i in mhi:
  for j in mwi:
    if not j in dic[i]:
      print(mw+mh)
      quit()

print(mh+mw-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
h, w, m = map(int, input().split())
hl=[0]*h
wl=[0]*w
mh=0
mw=0
mhi=deque([])
dic = {}
mwi=deque([])
#ans =[[0]*w for i in range(h)]
s = [list(map(int, input().split())) for i in range(m)]
 
for i in range(m):
  a, b = s[i]
  a-=1
  b-=1
  if not a in dic:
    #dic[a] = deque([b])
    dic[a] = [0]*w
    dic[a][b]=1
    
  else:
    dic[a][b]=1
 
  hl[a]+=1
  if hl[a]>mh:
    mh=hl[a]
    mhi = [a]
  elif hl[a]==mh:
    mhi.append(a)
  
  wl[b]+=1
  if wl[b]>mw:
    mw=wl[b]
    mwi=[b]
  elif wl[b]==mw:
    mwi.append(b)
 
  #ans[a][b]+=1 
for i in mhi:
  for j in mwi:
    if dic[i][j]==0:
      print(mh+mw)
      quit()
      
print(mh+mw-1)

Buggy submission (verdict: Runtime Error):
h, w, m = map(int, input().split())
hl=[0]*h
wl=[0]*w
ans =[[0]*w for i in range(h)]
for i in range(m):
  a, b = map(int, input().split())
  a-=1
  b-=1
  hl[a]+=1
  wl[b]+=1
  ans[a][b]+=1

mh = 0
mhi = []
for i in range(h):
  if hl[i]>mh:
    mh = hl[i]
    mhi=[i]
  if hl[i]==mh:
    mhi.append(i)

wh = 0
whi = []
for i in range(w):
  if wl[i]>wh:
    wh = wl[i]
    whi=[i]
  if wl[i]==wh:
    whi.append(i)

for i in mhi:
  for j in whi:
    if ans[i][j]==0:
      print(mh+wh)
      quit()
print(mh+wh-1)
Problem p02793 (python)

Fixed submission:
#

import sys
input=sys.stdin.readline

MOD=10**9+7
kl = [0]*(10**6+1)

            
def main():
    N=int(input())
    A=list(map(int,input().split()))
    if N==1:
        print(1)
        exit()
    for j in range(N):
        n=A[j]
        for i in range(2,int((n)**0.5)+1):
            if n%i==0:
                cnt=0
                while(n%i==0):
                    n//=i
                    cnt+=1
                if kl[i]<cnt:
                    kl[i]=cnt
        if n!=1:
            if kl[n]<1:
                kl[n]=1
                
    lcm=1
    for i in range(2,10**6+1):
        lcm*=pow(i, kl[i], MOD)

    modsum=0
    for i in range(N):
        modsum+=pow(A[i],MOD-2,MOD)

    ans = lcm*modsum%MOD
    print(ans)
    
    
    
if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
#

import sys
input=sys.stdin.readline

MOD=10**9+7
kl = [0]*(10**6+1)

            
def main():
    N=int(input())
    A=list(map(int,input().split()))
    if N==1:
        print(1)
        exit()
    for j in range(N):
        n=A[j]
        for i in range(2,int((n)**0.5)+1):
            if n%i==0:
                cnt=0
                while(n%i==0):
                    n/=i
                    cnt+=1
                if kl[i]<cnt:
                    kl[i]=cnt
        if n!=1:
            if kl[n]<1:
                kl[n]=1
                
    lcm=1
    for i in range(2,10**6+1):
        lcm*=pow(i, kl[i], MOD)

    modsum=0
    for i in range(N):
        modsum+=pow(A[i],MOD-2,MOD)

    ans = lcm*modsum%MOD
    print(ans)
    
    
    
if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
#

import sys
input=sys.stdin.readline

MOD=10**9+7
            
def main():
    N=int(input())
    A=list(map(int,input().split()))
    if N==1:
        print(1)
        exit()
    kl=[0]*(10**6+1)
    for j in range(N):
        n=A[j]
        for i in range(2,int((n)**0.5)+1):
            if n%i==0:
                cnt=0
                while(n%i==0):
                    n/=i
                    cnt+=1
                if kl[i]<cnt:
                    kl[i]=cnt
        if n!=1:
            if kl[n]<1:
                kl[n]=1
                
    lcm=1
    for i in range(2,10**6+1):
        lcm*=pow(i, kl[i], MOD)
    ans=0
    for i in range(N):
        ans+=pow(A[i],MOD-2,MOD)
        ans%=MOD
    print(lcm*ans%MOD)
    
    
    
if __name__=="__main__":
    main()
Problem p02793 (python)

Fixed submission:
import fractions
def LCM(a, b):
    return(a // fractions.gcd(a, b) * b)

n = int(input())
a = list(map(int, input().split()))
lc = 1;

for i in range(n):
    lc = LCM(lc, a[i])

res = 0;
for i in range(n):
    res = res + (lc // a[i])

print(res % 1000000007)

Buggy submission (verdict: Runtime Error):
import math
def LCM(a, b):
    return(a // math.gcd(a, b) * b)

n = int(input())
a = list(map(int, input().split()))
lc = 1;

for i in range(n):
    lc = LCM(lc, a[i])

res = 0;
for i in range(n):
    res = res + (lc // a[i])

print(res % 1000000007)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
lcm = 1

lc = np.lcm.reduce(a)

res = 0
for i in range(n):
    res = res + lc // a[i]
    res = res % 1000000007

print(res)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
lcm = 1

lc = mp.lcm.reduce(a)

res = 0
for i in range(n):
    res = res + lc // a[i]
    res = res % 1000000007

print(res)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
lcm = 1

lc = mp.lcm.reduce(a)

res = 0
for i in range(n):
    res = res + lc / a[i]
    res = res % 1000000007

print(res)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = []
lcm = 1
for i in range(n - 1):
    t = int(input())
    a.append(t)

lc = mp.lcm.reduce(a)

res = 0
for i in range(n - 1):
    res = res + lc / a[i]
    res = res % 1000000007

print(res)

Buggy submission (verdict: Runtime Error):
import numpy as np
     
n = int(input())
a = []
lcm = 1
for i in range(n - 1):
  t = int(input())
  a.append(t)
      
lc = np.lcm.reduce(a)
     
res = 0;
for i in range(n):
  res = res + lc / a[i];
  res = res % 1000000007
     
print(res)

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = []
lcm = 1
for i in range(n):
  t = int(input())
  a.append(t)
  
lc = np.lcm.reduce(a)

res = 0;
for i in range(n):
  res = res + lc / a[i];
  res = res % 1000000007

print(res)
Problem p02623 (python)

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

prefix_A = [0] * (N + 1)
for i, a in enumerate(A, 1):
    prefix_A[i] = prefix_A[i - 1] + a
prefix_B = [0] * (M + 1)
for j, b in enumerate(B, 1):
    prefix_B[j] = prefix_B[j - 1] + b


res = 0
for i in range(N + 1):
    cur = prefix_A[i]
    if cur == K:
        res = max(i, res)
    elif cur < K:
        left = 0
        right = M + 1
        while right - left > 1:
            mid = (left + right) // 2
            if cur + prefix_B[mid] <= K:
                left = mid
            else:
                right = mid
        res = max(res, i + left)


print(res)

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

sys.setrecursionlimit(10 ** 5)


N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
n, m = map(len, (A, B))


@lru_cache(None)
def dp(i, j, cur):
    if cur > K:
        return 0
    elif i >= n:
        if j < m and cur + B[j] <= K:
            return dp(i, j + 1, cur + B[j]) + 1
        else:
            return 0
    elif j >= m:
        if i < n and cur + A[i] <= K:
            return dp(i + 1, j, cur + A[i]) + 1
        else:
            return 0
    else:
        res = float('-inf')
        if cur + A[i] <= K:
            res = max(1 + dp(i + 1, j, cur + A[i]), res)
        if cur + B[j] <= K:
            res = max(1 + dp(i, j + 1, cur + B[j]), res)
        if res == float('-inf'):
            return 0
        else:
            return res


print(dp(0, 0, 0))

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

sys.setrecursionlimit(10 ** 5)


N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
n, m = map(len, (A, B))


@lru_cache(None)
def dp(i, j, cur):
    if cur > K:
        return 0
    elif i >= n:
        if j < m and cur + B[j] <= K:
            return dp(i, j + 1, cur + B[j]) + 1
        else:
            return 0
    elif j >= m and cur + A[i] <= K:
        if i < n:
            return dp(i + 1, j, cur + A[i]) + 1
        else:
            return 0
    else:
        res = float('-inf')
        if cur + A[i] <= K:
            res = max(1 + dp(i + 1, j, cur + A[i]), res)
        if cur + B[j] <= K:
            res = max(1 + dp(i, j + 1,  cur + B[j]), res)
        if res == float('-inf'):
            return 0
        else:
            return res


print(dp(0, 0, 0))
Problem p02629 (python)

Fixed submission:
N = int(input())
res = []
while N:
    r = N % 26
    if r == 0:
        r = 26
    res.append(chr(r + 96))
    if r == 26:
        N -= 1
    N //= 26
res.reverse()
print(''.join(res))

Buggy submission (verdict: Runtime Error):
N = int(input())
mapping = 'zabcdefghijklmnopqrstuvwx'
res = []
for i in range(1, 99):
    if N <= 26 ** i:
        for j in range(i):
            res.append(mapping[N % 26])
            N //= 26
        break
    else:
        N -= 26 ** i
print(''.join(res))
Problem p02661 (python)

Fixed submission:
import math


def median(array):
    if N % 2:
        return array[N // 2]
    else:
        return sum(array[N // 2 - 1: N // 2 + 1])


N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
x = median(A)
y = median(B)
print(y - x + 1)

Buggy submission (verdict: Runtime Error):
import math


def median(array):
    if N % 2:
        return array[N // 2]
    else:
        return sum(array[N // 2 - 1: N // 2 + 1]) / 2


N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
x = median(A)
y = median(B)
if N % 2:
    print(y - x + 1)
else:
    temp = math.ceil(y) - math.floor(x)
    print(2 * temp + 1))
Problem p02831 (python)

Fixed submission:
def gcd(x, y):
    while y > 0:
        x, y = y, x % y
    return x


A, B = map(int, input().split())
print(A * B // gcd(A, B))

Buggy submission (verdict: Runtime Error):
import math

A, B = map(int, input().split())
print(A * B // math.gcd(A, B))
Problem p02912 (python)

Fixed submission:
import heapq

n, m = map(int, input().split())
prices = [-int(p) for p in input().split()]
heapq.heapify(prices)
for _ in range(m):
  p = heapq.heappop(prices)
  heapq.heappush(prices, p / 2)
print(-sum(int(p) for p in prices))

Buggy submission (verdict: Runtime Error):
import heapq

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    p = heapq._heappop_max(prices)
    heapq.heappush(prices, p // 2)
print(sum(prices))

Buggy submission (verdict: Runtime Error):
import heapq

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    p = heapq._heappop_max(prices) // 2
    prices.append(p)
    heapq._siftdown_max(prices, 0, n - 1)
print(sum(prices))

Buggy submission (verdict: Runtime Error):
import heapq

n, m = map(int, input().split())
prices = [int(p) for p in input().split()]
heapq._heapify_max(prices)
for _ in range(m):
    p = heapq._heappop_max(prices) // 2
    heapq.heappush(prices, p)
print(sum(prices))