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

Fixed submission:
#ABC145D

MOD = 10 ** 9 + 7
import math
x,y = map(int,input().split())
a,b = -1,-1

for i in range(x+1):
    m = 0
    if (x-i) % 2 == 0:
        m = (x-i) // 2
        if 2*i + m == y:
            if i >= 0 and m >= 0:
                a = i
                b = m
                break
    else:
        continue
        
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def com(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod  
        
        
if a == -1 and b == -1:
    print(0)
else:
    print(com(a+b,a,MOD))

Buggy submission (verdict: Runtime Error):
#ABC145D

MOD = 10 ** 9 + 7
import math
x,y = map(int,input().split())
a,b = -1,-1

for i in range(x+1):
    m = 0
    if (x-i) % 2 == 0:
        m = (x-i) // 2
        if 2*i + m == y:
            if i >= 0 and m >= 0:
                a = i
                b = m
                break
    else:
        continue
        
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],mod-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def com(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod  
        
        
if a == -1 and b == -1:
    print(0)
else:
    print(com(a+b,a,MOD))

Buggy submission (verdict: Runtime Error):
#ABC145D

MOD = 10 ** 9 + 7
import math
x,y = map(int,input().split())
a,b = -1,-1

for i in range(x):
    m = 0
    if (x-i) % 2 == 0:
        m = (x-i) // 2
        if 2*i + m == y:
            if i >= 0 and m >= 0:
                a = i
                b = m
                break
    else:
        continue
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],mod-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def com(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod  
        
        
if a == -1 and b == -1:
    print(0)
else:
    print(com(a+b,a,MOD))
Problem p03634 (python)

Fixed submission:
from collections import deque
import sys
INF = 11414191981036436433-4

n = int(input())
g = [[] for i in range(n)]
for v in range(n-1):
    a,b,c = map(int,input().split())
    g[a-1].append((b-1,c))
    g[b-1].append((a-1,c))
    
q,k = map(int,input().split())
k -= 1

r = [INF]*n
que = deque([k])
r[k] = 0
while que:
    v = que.popleft()
    rr = r[v]
    for w,x in g[v]:
        if r[w] == INF:
            r[w] = rr + x
            que.append(w)
            
for i in range(q):
    d,e = map(int,input().split())
    print(r[d-1] + r[e-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
INF = 11414191981036436433-4

n = int(input())
g = [[] for i in range(n)]
for v in range(n-1):
    a,b,c = map(int,input().split())
    g[a-1].append((b-1,c))
    g[b-1].append((a-1,c))
    
q,k = map(int,input().split())
k -= 1

r = [INF]*n
que = deque([k])
r[k] = 0
while que:
    v = que.popleft()
    rr = r[v]
    for w,x in G[v]:
        if r[w] == INF:
            r[w] = rr + x
            que.append(w)
            
for i in range(q):
    d,e = map(int,input().split())
    print(r[d-1] + r[e-1])

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

N = int(input())
prv = [None]*N
G = [[] for i in range(N)]
for v in range(N-1):
    a,b,c = map(int,input().split())
    aa = min(a,b)-1
    bb = max(a,b)-1
    G[aa].append((bb,c))
    prv[bb] = aa

depth = [0]*N
r = [0]*N
que = deque([0])
while que:
    v = que.popleft()
    d = depth[v]
    rr = r[v]
    for w,x in G[v]:
        depth[w] = d + 1
        r[w] = rr + x
        que.append(w)
        
LV = (N-1).bit_length()
def construct(prv):
    kprv = [prv]
    S = prv
    for k in range(LV):
        T = [0]*N
        for i in range(N):
            if S[i] is None:
                continue
            T[i] = S[S[i]]
        kprv.append(T)
        S = T
    return kprv

def lca(u, v, kprv, depth):
    dd = depth[v] - depth[u]
    if dd < 0:
        u, v = v, u
        dd = -dd

    # assert depth[u] <= depth[v]
    for k in range(LV+1):
        if dd & 1:
            v = kprv[k][v]
        dd >>= 1

    # assert depth[u] == depth[v]
    if u == v:
        return u

    for k in range(LV-1, -1, -1):
        pu = kprv[k][u]; pv = kprv[k][v]
        if pu != pv:
            u = pu; v = pv

    # assert kprv[0][u] == kprv[0][v]
    return kprv[0][u]


kprv = construct(prv)

Q,k = map(int, input().split())
k -= 1
for q in range(Q):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    a1 = lca(u, k, kprv, depth)
    a2 = lca(v, k, kprv, depth)
    aa1 = r[u] + r[k] - 2*r[a1]
    aa2 = r[k] + r[v] - 2*r[a2]
    print(aa1+aa2)
Problem p03724 (python)

Fixed submission:
n,m = map(int,input().split())
from collections import Counter

s = []
for _ in range(m):
    a,b = map(int,input().split())
    s.append(a)
    s.append(b)
    
c = Counter(s)
d = list(c.values())

ans = "YES"
for i in d:
    if i % 2 == 1:
        ans = "NO"
        break
        
print(ans)

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

s = []
for _ in range(n):
    a,b = map(int,input().split())
    s.append(a)
    s.append(b)
    
c = Counter(s)
d = list(c.values())

ans = "YES"
for i in d:
    if i % 2 == 1:
        ans = "NO"
        break
        
print(ans)
Problem p02819 (python)

Fixed submission:
def main():
  N = int(input())
  
  print(search(N))
 
def search(x):
  
  ints = list(range(2,x))
  
  # 順に確認する
  for i in ints:
    if x%i==0:
      return search(x+1)
    elif x < i**2:
      break
    
  return x

main()

Buggy submission (verdict: Runtime Error):
import math
 
def main():
  N = int(input())
  
  print(search(N))
 
def search(x):
  
  ints = list(range(2,x))
  
  # 順に確認する
  for i in ints:
    if x%i==0:
      return search(x+1)
  	elif x < i**2:
      break
    
  return x

Buggy submission (verdict: Runtime Error):
import math
 
def main():
  N = int(input())
  
  print(search(N))
 
def search(x):
  
  ints = list(range(2,x))
  
  # 順に確認する
  for i in ints:
    if x%i==0:
      return seartch(x+1)
  	elif x < i**2:
      break
    
  return x

Buggy submission (verdict: Runtime Error):
import math
 
def main():
  N = int(input())
  
  print(search(N))
 
def search(x):
  
  ints = list(range(2,x))
  
  # 順に確認する
  for i in ints:
    if x%i==0:
      seartch(x+1)
  	elif x < i**2:
      break
    
  return x

Buggy submission (verdict: Runtime Error):
import math

def main():
  N = int(input())
  
  if N==2:
    print(2)
  else:
    print(search(N))

# xは奇数を前提
def search(x):
  
  # 2は確認不要
  ints = list(range(3,x))
  
  # 順に確認する
  for i in ints:
    
    
    if x%i==0:
      seartch(x+2)
  	elif x < i**2:
      break
    
  return x
Problem p03038 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
from operator import itemgetter
import bisect


def solve(N: int, M: int, A: "List[int]", BC):
    A.sort()
    BC.sort(key=itemgetter(1), reverse=True)
    idx = 0
    i = 0
    for i in range(M):
        B, C = BC[i]
        nidx = idx+B if idx+B < len(A) else len(A)
        if A[nidx-1] < C:
            for j in range(idx, nidx):
                A[j] = C
            idx += B
        else:
            for j in range(idx, nidx):
                if A[j] < C:
                    A[j] = C
            break

    ans = 0
    for a in A:
        ans += a
    print(ans)

    return


# Generated by 1.1.4 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
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    BC = []
    for _ in range(M):
        BC.append(list(map(int, input().split())))
    solve(N, M, A, BC)

if __name__ == '__main__':
    main()

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


def solve(N: int, M: int, A: "List[int]", BC):
    A.sort()
    BC.sort(key=itemgetter(1), reverse=True)
    idx = 0
    i = 0
    while i < M:
        B, C = BC[i]
        nidx = idx+B if idx+B < len(A) else len(A) - 1
        if A[nidx] < C:
            for j in range(idx+B):
                A[j] = C
            idx += B
            i += 1
        else:
            for j in range(nidx):
                if A[j] < C:
                    A[j] = C
            break

    ans = 0
    for a in A:
        ans += a
    print(ans)

    return


# Generated by 1.1.4 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
    M = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    BC = []
    for _ in range(M):
        BC.append(list(map(int, input().split())))
    solve(N, M, A, BC)

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

Fixed submission:
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
pos = [None]*(H*W+1)
for i, elem in enumerate(A):
    for j, a in enumerate(elem):
        pos[a] = (i, j)
acc = [[] for _ in range(D+1)]
for i in range(1, D+1):
    tmp = i
    s = 0
    acc[i].append(s)
    while tmp <= H*W-D:
        s += abs(pos[tmp][0]-pos[tmp+D][0])+abs(pos[tmp][1]-pos[tmp+D][1])
        acc[i].append(s)
        tmp += D

for _ in range(Q):
    L, R = map(int, input().split())
    print(acc[(R-1) % D+1][(R-R % D)//D-(R % D == 0)] -
          acc[(R-1) % D+1][(L-L % D)//D-(L % D == 0)])

Buggy submission (verdict: Runtime Error):
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
pos = [None]*(H*W+1)
for i, elem in enumerate(A):
    for j, a in enumerate(elem):
        pos[a] = (i, j)
acc = [[] for _ in range(D+1)]
for i in range(1, D+1):
    tmp = i
    s = 0
    acc[i].append(s)
    while tmp <= H*W-D:
        s += abs(pos[tmp][0]-pos[tmp+D][0])+abs(pos[tmp][1]-pos[tmp+D][1])
        acc[i].append(s)
        tmp += D

for _ in range(Q):
    L, R = map(int, input().split())
    print(acc[(R-1) % D+1][(R-R % D-1)//D+1] -
          acc[(R-1) % D+1][(L-L % D-1)//D+1])
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    G[a].append((b, c))
    G[b].append((a, c))
Q, K = map(int, input().split())


d = [-1]*(N+1)


def dfs(v, c):
    d[v] = c
    for nv, cost in G[v]:
        if d[nv] == -1:
            dfs(nv, cost+c)

dfs(K, 0)

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

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


d = [-1]*(N+1)


def dfs(v, c):
    d[v] = c
    for nv, cost in G[v]:
        if d[nv] == -1:
            dfs(nv, cost+c)

dfs(K, 0)

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

Fixed submission:
D,T,S=map(int, input().split())

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

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

if S*T>=D:
    print('Yes')
else:
    Print('No')
Problem p02597 (python)

Fixed submission:
import numpy as np

N=int(input())
c=np.array(list(input()))
n=np.count_nonzero(c == 'R')
i=0
j=N-1
cnt=0
if N==n:
    print(cnt)
    exit(0)
while 1:
    while c[i]!='W' and i<n:
        i+=1
    while c[j]!='R' and j>n-1:
        j-=1
    if i>=n or j<n:
        print(cnt)
        exit(0)
    temp=c[i]
    c[i]=c[j]
    c[j]=temp
    cnt+=1

print(cnt)

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

N=int(input())
c=np.array(list(input()))
n=np.count_nonzero(c == 'R')
i=0
j=N-1
cnt=0
if N==n:
    print(cnt)
    exit(0)
while 1:
    while c[i]!='W' and i<n:
        i+=1
    while c[j]!='R':
        j-=1
    if i>=n:
        print(cnt)
        exit(0)
    temp=c[i]
    c[i]=c[j]
    c[j]=temp
    cnt+=1

print(cnt)
Problem p02753 (python)

Fixed submission:
i=input()
j=i[0]
k=0

for n in range(2):
	if i[n+1]!=i[0]:
		k=1
if k==0:
	print('No')
else:
	print('Yes')

Buggy submission (verdict: Runtime Error):
i=input()
j=i[0]
k=0

for n in range(2):
  if i[n+1]!=j:
	print('Yes')
	k=1
  
if k=0:
  print('No')
Problem p02759 (python)

Fixed submission:
n=input()
N=float(n)
k=N%2
if k==0:
    print(round(N/2.0))
else:
    print(round(N/2+1/2.0))

Buggy submission (verdict: Runtime Error):
k=N%2
if k==0:
    print(round(N/2.0))
else:
    print(round(N/2+1/2.0))
Problem p02835 (python)

Fixed submission:
a = [int(i) for i in input().split()]

print('bust' if sum(a) > 21 else 'win')

Buggy submission (verdict: Runtime Error):
n = int(input())
x = []
y = []

for i in range(n):
    a = int(input())
    x.append([])
    y.append([])
    for j in range(a):
        u, v = map(int, input().split())
        x[i].append(u)
        y[i].append(v)
ans = 0
for i in range(2 ** n):
    jdg = [False] * n
    used = [False] * n
    end = False
    for j in range(n):
        if ((i >> j) & 1):
            jdg[j] = True
    for j in range(n):
        for k in range(n):
            if ((not jdg[k]) or used[k]):
                continue
            used[k] = True
            for l in range(len(x[k])):
                if (y[k][l] == 1):
                    jdg[x[k][l] - 1] = True
                elif (jdg[x[k][l] - 1]):
                    end = True
                    break
            if (end):
                break
        if (end):
            break
    if (end):
        continue
    ans = max(sum(jdg), ans)

print(ans)
Problem p02552 (python)

Fixed submission:
x = int(input())
print(1-x)

Buggy submission (verdict: Runtime Error):
x = int(input())
if x == 0:
  print(1)
elif x == 1:
  print(0)
else:
  break
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
if a >= 3200:
  print(s)
else:
  print('red')

Buggy submission (verdict: Runtime Error):
n, q = map(int,input().split())
tree = [[] for i in range(n)]
v = [0]*n
for i in range(n-1):
    a1,b1 = [int(i) for i in input().split()]
    tree[a1-1].append(b1)
for i in range(q):
    p1,x1 = [int(i) for i in input().split()]
    v[p1 - 1] += x1
for i in range(n):
    for j in range(len(tree[i])):
        v[tree[i][j]-1] += v[i]
for i in range(n):
    print(str(v[i]) +" ",end="")
Problem p02948 (python)

Fixed submission:
from heapq import heappush, heappop
n,m = map(int,input().split())
jobs = [[] for i in range(100001)]
for i in range(n):
    a1,b1 = map(int,input().split())
    jobs[a1].append(b1)

reward = 0
heapsort = []
for daysLeft in range(1,m+1):
    if len(jobs[daysLeft]) != 0:
        for i in jobs[daysLeft]:
            heappush(heapsort,-i)
    if len(heapsort) > 0:
        reward += -heappop(heapsort)
print(reward)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
jobs = [[] for i in range(100001)]
for i in range(n):
    a1,b1 = map(int,input().split())
    jobs[a1 - 1].append(b1)
result = 0
for i in range(m):
    jobs_1 = 0
    jobs_2 = 0
    reward = 0
    for j in range(i+1):
        if len(jobs[j]) != 0:
            reward = max(reward,max(jobs[j]))
            jobs_1 = j
            jobs_2 = jobs[j].index(max(jobs[j]))
    if reward != 0:
        result += reward
        del jobs[jobs_1][jobs_2]
print(result
Problem p02835 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a + b + c >= 22:
  print("bust")
else:
  print("win")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
ig a + b + c >= 22:
  print("bust")
else:
  print("win")
Problem p03250 (python)

Fixed submission:
a, b, c = sorted(map(int, input().split(" ")))
print(c * 10 + a + b)

Buggy submission (verdict: Runtime Error):
a, b, c = sorted(map(int(), input().split(" ")))
print(c * 10 + a + b)
Problem p03805 (python)

Fixed submission:
n, m = 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)

ret = 0
def walk(node, visited):
    global ret
    tmp = visited + [node]
    if len(tmp) == n:
        ret += 1 
    for nd in g[node]:
        if nd not in tmp:
            walk(nd, tmp)
walk(1, [])
print(ret)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
g = [[] for _ in range(M + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
def walk(cur, visited):
    global ans
    tmp = visited + [cur]
    if len(tmp) == N:
        ans += 1
    for nex in g[cur]:
        if nex not in tmp:
            walk(nex, tmp)
walk(1, [])
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
g = [list() for _ in range(M + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
def walk(cur, visited):
    global ans
    tmp = visited + [cur]
    if len(tmp) == N:
        ans += 1
    for nex in g[cur]:
        if nex not in tmp:
            walk(nex, tmp)
walk(1, [])
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
g = [list() for _ in range(M + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
def walk(cur, visited):
    global ans, g, N, M
    tmp = visited + [cur]
    if len(tmp) == N:
        ans += 1
    for nex in g[cur]:
        if nex not in tmp:
            walk(nex, visited + [cur])
walk(1, [])
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
g = [list() for _ in range(M + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
def walk(cur, visited):
    global ans
    tmp = visited + [cur]
    if len(tmp) == N:
        ans += 1
    for nex in g[cur]:
        if nex not in tmp:
            walk(nex, visited + [cur])
walk(1, [])
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
g = [list() for _ in range(M + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

ans = 0
def walk(cur, visited):
    global ans
    if cur == N:
        ans += 1
        return
    visited.append(cur)
    for nex in g[cur]:
        if nex not in visited:
            walk(nex, visited)
walk(1, [])
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から選んでみる
minutes_a = 0
count_a = 0
for i in range(N):
    if minutes_a + A[i] > K:
        break
    minutes_a += A[i]
    count_a += 1

ans = count_a
minutes_b = 0
count_b = 0

for i in range(M):
    if minutes_a + minutes_b + B[i] > K:
        found = False
        while count_a > 0:
            minutes_a -= A[count_a - 1]
            count_a -= 1
            if minutes_a + minutes_b + B[i] <= K:
                minutes_b += B[i]
                count_b += 1
                found = True
                break
        if not found:
            break
    else:
        minutes_b += B[i]
        count_b += 1
    ans = max(ans, count_a + count_b)

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()))

# 全部Aから選んでみる
minutes_a = 0
count_a = 0
for i in range(N):
    if minutes_a + A[i] > K:
        break
    minutes_a += A[i]
    count_a += 1

minutes_b = 0
count_b = 0

if minutes_a < K:
    for i in range(M):
        if minutes_a + minutes_b + B[i] > K:
            break
        minutes_b += B[i]
        count_b += 1

for i in range(count_b, M):
    if minutes_a + minutes_b + B[i] > K:
        if count_a > 0 and minutes_a - A[count_a - 1] + minutes_b + B[i] <= K:
            minutes_a -= A[count_a - 1]
            count_a -= 1
            minutes_b += B[i]
            count_b += 1
            continue
        else:
            break
    minutes_b += B[i]
    count_b += 1

a_max = count_a + count_b

# 全部Bから選んでみる
minutes_b = 0
count_b = 0
for i in range(M):
    if minutes_b + B[i] > K:
        break
    minutes_b += B[i]
    count_b += 1

minutes_a = 0
count_a = 0

if minutes_b < K:
    for i in range(N):
        if minutes_b + minutes_a + A[i] > K:
            break
        minutes_a += A[i]
        count_a += 1

for i in range(count_a, N):
    if minutes_b + minutes_a + A[i] > K:
        if count_b > 0 and minutes_b - B[count_b - 1] + minutes_a + A[i] <= K:
            minutes_b -= B[count_a - 1]
            count_b -= 1
            minutes_a += A[i]
            count_a += 1
            continue
        else:
            break
    minutes_a += A[i]
    count_a += 1

print(max(a_max, count_a + count_b))

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

# 全部Aから選んでみる
minutes_a = 0
count_a = 0
for i in range(N):
    if minutes_a + A[i] > K:
        break
    minutes_a += A[i]
    count_a += 1

max_count = count_a
minutes_b = 0
count_b = 0

while count_a > 0:
    for i in range(count_b, M):
        if minutes_a - A[count_a - 1] + minutes_b + B[i] > K:
            break
        minutes_a -= A[count_a - 1]
        count_a -= 1
        minutes_b += B[i]
        count_b += 1

for i in range(count_b, M):
    if minutes_a + minutes_b + B[i] > K:
        minutes_b += B[i]
        count_b += 1


print(count_a + count_b)
Problem p02989 (python)

Fixed submission:
N = int(input())
d = list(map(int, input().split()))
d.sort()

abc = 0
arc = N

ans = 0
for k in range(1, 10 ** 5 + 1):
    while True:
        if abc >= N:
            break
        elif d[abc] < k:
            abc += 1
            arc -= 1
        else:
            break
    if abc == arc:
        ans += 1
    elif abc > arc:
        break

print(ans)

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

abc = 0
arc = N

ans = 0
for k in range(1, 10 ** 5):
    while True:
        if d[abc] < k:
            abc += 1
            arc -= 1
        else:
            break
    if abc == arc:
        ans += 1
    elif abc > arc:
        break

print(ans)