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

Fixed submission:
X = int(input())

import math
import sys

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(X) == True:
        print(X)
        sys.exit()
    X+=1

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

import math
#----エラトステネスの篩--------
def get_primenumber(number):
    prime_list = []
    #2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2,number+1))
    while True:
      #search_listの先頭の値が√nの値を超えたら処理終了
      if search_list[0] > math.sqrt(number):
        #prime_listにsearch_listを結合
        prime_list.extend(search_list)
        break
      else:
        #search_listの先頭をprime_listに入れる
        head_num = search_list[0]
        prime_list.append(head_num)
        #search_listの先頭をpopする
        search_list.pop(0)
        #head_numの倍数を取り除く
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list
  
  num_list = get_primenumber(10**5+1)
  
  import sys

for i in range(len(num_list)):
    if X <= num_list[i]:
        print(num_list[i])
        sys.exit()
Problem p02833 (python)

Fixed submission:
n = int(input())
if n % 2:
  print(0)
  quit()
ans = 0
for i in range(1,36):
  ans += (n // (2 * 5 ** i))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
 
count = 0
 
if n%2 == 1:
    print(0)
else:
    for i im range(1,100):
        if n < 2*5**i:
            break
        else:
            count = count + (n)//(2*5**i)
            i += 1
        
print(count)
Problem p02880 (python)

Fixed submission:
N = int(input())

count = 0

for i in range(1,10):
    if N%i == 0 and N//i < 10:
        count+=1
        
if count > 0:
    print('Yes')
else:
    print('No')

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

divisors = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        divisors.append(i)
        if i != n // i:
               divisors.append(n//i)
            
print(min(divisors[-1]+divisors[-2]-2,divisors[-3]+divisors[-4]-2))
Problem p02881 (python)

Fixed submission:
n = int(input())

divisors = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        divisors.append(i)
        if i != n // i:
               divisors.append(n//i)

divisors.append(divisors[-1])

aaa = 0
bbb = 10**12+1
j = 0

for i in range(1,len(divisors)//2+1):
    aaa = divisors[j]+divisors[j+1]-2
    if aaa < bbb:
        bbb = aaa
    j += 2
    
print(bbb)

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

divisors = []
for i in range(1, int(n**0.5)+1):
    if n % i == 0:
        divisors.append(i)
        if i != n // i:
               divisors.append(n//i)


if len(divisors) > 2:
    print(min(divisors[-1]+divisors[-2]-2,divisors[-3]+divisors[-4]-2))
else:
    print(divisors[-1]+divisors[-2]-2)
Problem p02897 (python)

Fixed submission:
N = int(input())
print(1-(N//2)/N)

Buggy submission (verdict: Runtime Error):
from sympy import nextprime
A,B = list(map(int,input().split()))
 
aaa = []
 
for i in range(1,min(A,B)):
    if A%i == 0 and B%i == 0:
        aaa.append(i)
        
count = 0
 
for i in range(len(aaa)):
    if isprime(aaa[i]) == True:
        count += 1
        
print(count+1)
Problem p02915 (python)

Fixed submission:
N = int(input())
print(N*N*N)

Buggy submission (verdict: Runtime Error):
n=int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
count = 0
for i in range(n):
    index=a_list[i]
    count += b_list[index - 1]
#     print(count)
    if i !=0:
        if a_list[i] == a_list[i-1] + 1:
            count += c_list[a_list[i-1]-1]
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
answer = 0
 
for i in range(N):
  index = A[i]
  answer = answer + B[index-1]

  if i != 0:
    if A[i] == A[i-1]+1:
      answer = answer + C[A[i-1]-1]
      
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
answer = 0
 
for i in range(N):
  answer = answer + B[i]
  
for i in range(N):
  if i != 0:
    if A[i] == A[i-1]+1:
      answer = answer + C[a[i-1]-1]
    
print(answer)
Problem p02916 (python)

Fixed submission:
n=int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))
count = 0
for i in range(n):
    index=a_list[i]
    count += b_list[index - 1]
#     print(count)
    if i !=0:
        if a_list[i] == a_list[i-1] + 1:
            count += c_list[a_list[i-1]-1]
print(count)

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

answer = 0

for i in range(N):
  answer = answer + B[i]
  
for i in range(N):
  if A[i]+1 == A[i+1]
    answer = answer + C[i]
    
print(answer)
Problem p02970 (python)

Fixed submission:
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
while hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human)

Buggy submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
while hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human) = kanshi

Buggy submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
hani = 2*D+1
haniwhile hani < N:
    hani = hani + (2*D+1)
    human +=1
    
print(human) = kanshi

Buggy submission (verdict: Runtime Error):
N,D = list(map(int,input().split()))
human = 1
kanshi = 2*D+1
haniwhile hani < N:
    hani = hani + kanshi
    human +=1
    
print(human) = kanshi
Problem p03075 (python)

Fixed submission:
antenna = [int(input()) for i in range(5)]
k = int(input())

if max(antenna) - min(antenna) <= k:
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
antenna = [int(input()) for i in range(5)]
k = int(input())

if max(antenna) - min(antenna) =< k:
    print('Yay!')
else:
    print(':(')
Problem p03107 (python)

Fixed submission:
S = input()
print(2 * min(S.count('1'),S.count('0')))

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

S = list(S)

from collections import Counter
c = Counter(S)
d = c.most_common()

print(2*min(d[0][1],d[1][1]))
Problem p02679 (python)

Fixed submission:
from math import gcd
MOD = 10**9 + 7
n = int(input())
zero = 0
cnt = dict()
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0 or (y == 0 and x < 0):
        x *= -1
        y *= -1
    rot_90 = 1 if x <= 0 else 0
    if rot_90:
        x, y = y, -x
    try:
        cnt[(x, y)][rot_90] += 1
    except KeyError:
        cnt[(x, y)] = [int(not rot_90), rot_90]

ans = 1
for s, t in cnt.values():
    now = 1
    now += (pow(2, s, MOD) - 1) % MOD
    now += (pow(2, t, MOD) - 1) % MOD
    ans *= now
ans -= 1
ans += zero
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
from math import gcd
MOD = 10**9 + 7
n = int(input())
zero = 0
cnt = defaultdict()
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0 or (y == 0 and x < 0):
        x *= -1
        y *= -1
    rot_90 = 1 if x <= 0 else 0
    if rot_90:
        x, y = y, -x
        cnt[(x, y)][rot_90] += 1

ans = 1
for s, t in cnt.values():
    now = 1
    now += (pow(2, s, MOD) - 1) % MOD
    now += (pow(2, t, MOD) - 1) % MOD
    ans *= now
ans -= 1
ans += zero
print(ans % MOD)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from math import gcd
MOD = 10**9 + 7
n = int(input())
zero = 0
cnt = dict()
for i in range(n):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0 or (y == 0 and x < 0):
        x *= -1
        y *= -1
    rot_90 = 1 if x <= 0 else 0
    if rot_90:
        x, y = y, -x
        cnt[(x, y)][rot_90] += 1

ans = 1
for s, t in cnt.values():
    now = 1
    now += (pow(2, s, MOD) - 1) % MOD
    now += (pow(2, t, MOD) - 1) % MOD
    ans *= now
ans -= 1
ans += zero
print(ans % MOD)
Problem p02695 (python)

Fixed submission:
import itertools
n, m, q = map(int, input().split())
A = itertools.combinations_with_replacement(range(1, m+1), n)
quads = [[int(i) for i in input().split()] for j in range(q)]
max_p = 0
for a in A:
    p = 0
    for quad in quads:
        if a[quad[1] - 1] - a[quad[0] - 1] == quad[2]:
            p += quad[3]
    if max_p < p:
        max_p = p
print(max_p)

Buggy submission (verdict: Runtime Error):
import itertools
n, m, q = map(int, input().split())
A = itertools.product(range(1, m + 1), repeat=m)
quads = [[int(i) for i in input().split()] for j in range(q)]
max_p = 0
for a in A:
    p = 0
    for quad in quads:
        if a[quad[1] - 1] - a[quad[0] - 1] == quad[2]:
            p += quad[3]
    if max_p < p:
        max_p = p
print(max_p)
Problem p02712 (python)

Fixed submission:
n = int(input())
sum = 0
for i in range(1, n + 1):
    if i % 3 != 0 and i % 5 != 0:
        sum += i
print(sum)

Buggy submission (verdict: Runtime Error):
n = int(input())
print(sum(i for i in range(i, n + 1) if i % 3 and i % 5))
Problem p02725 (python)

Fixed submission:
k, n = map(int, input().split())
a = [int(i) for i in input().split()]
diff_a = [0] * n
diff_a[0] = (a[0] + k) - a[n - 1]
for i in range(1, n):
    diff_a[i] = a[i] - a[i - 1]
print(k - max(diff_a))

Buggy submission (verdict: Runtime Error):
k, n = map(int, input().split())
a = list(map(int, input().split())) + [k + a[0]]
print(k - max([a[i + 1] - a[i] for i in range(n)]))

Buggy submission (verdict: Runtime Error):
k, n = map(int, input().split())
a = list(map(int, input().split())) + [k + a[0]]
print(k - max([a[i + 1] - a[i] for i in range(n)]))

Buggy submission (verdict: Runtime Error):
k, n = map(int, input().split())
a = list(map(int, input().split())) + [k + a[0]]
print(k - max([a[i + 1] - a[i] for i in range(n)]))
Problem p02779 (python)

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

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = [int(i) for i in input().split()]
maxp = 0
for i in range(n - k + 1):
    sump = sum(p[i: i + k])
    if maxp < sump:
        maxp = sump
        j = i
print((maxp + k) / 2)
Problem p02792 (python)

Fixed submission:
n = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for k in range(1, n + 1):
    c[int(str(k)[0])][int(str(k)[-1])] += 1

cnt = 0
for i in range(10):
    for j in range(10):
        cnt += c[i][j] * c[j][i]
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = [[0 for i in range(10)] for j in range(10)]
for k in range(1, n + 1):
    i, j = int(str_k[0]), int(str_k[-1])
    c[int(str(k)[0])][int(str(k)[-1])] += 1

cnt = 0
for i in range(10):
    for j in range(10):
        cnt += c[i][j] * c[j][i]
print(cnt)
Problem p02819 (python)

Fixed submission:
import math
def is_prime(n):
    if n == 2:
        return True
    if (n < 2) or (n % 2 == 0):
        return False
    stop = math.floor(math.sqrt(n)) + 1
    for i in range(3, stop, 2):
        if n % i == 0:
            return False
    return True

x = int(input())
while not is_prime(x):
    x += 1
print(x)

Buggy submission (verdict: Runtime Error):
def is_prime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return n != 1:
        

x = int(input())
while not is_prime(x):
    x += 1
print(x)
Problem p02832 (python)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
count = 0
for i in range(n):
    if a[i] == count + 1:
        count += 1
if count:
    print(n - count)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
a = deque([int(i) for i in input().split()])
count = 1
while a:
    try:
        index = a.index(count)
        count += 1
        a = a[index:]
    except ValueError:
        if count == 1:
            ans = -1
        else:
            ans = n - (count - 1)
        a = []
print(ans)
Problem p02860 (python)

Fixed submission:
n = int(input())
s = input()
flag = 1

if n % 2:
    print('No')
else:
    for i in range(n//2):
        if s[i] != s[n//2 + i]:
            flag = 0
    if flag:
        print('Yes')
    else:
        print('No')

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

if n % 2:
    for i in range(n):
        if s[i] != s[n//2 + i]:
            flag = 0
    if flag:
        print('Yes')
    else:
        print('No')
else:
        print('No')

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

if n % 2:
    print('No')
else:
    for i in range(n):
        if s[i] != s[n/2 + i]:
            flag = 0
    if flag:
        print('Yes')
    else:
        print('No')
Problem p02881 (python)

Fixed submission:
from math import sqrt
n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

Buggy submission (verdict: Runtime Error):
n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

Buggy submission (verdict: Runtime Error):
n = int(input())
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)
Problem p03038 (python)

Fixed submission:
n, m = map(int, input().split())
cards = sorted(list(map(int, input().split())))
ope = [list(map(int, input().split())) for i in range(m)]
ope.sort(key=lambda x: x[1], reverse=True)
i, j, k = 0, 0, 0
while i < n and j < m and cards[i] < ope[j][1]:
    cards[i] = ope[j][1]
    i += 1
    k += 1
    if k >= ope[j][0]:
        j += 1
        k = 0
print(sum(cards))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
rep = sorted([tuple(map(int, input().split())) for i in range(m)], key= lambda x: -x[1])
rep_n = min(n, sum(ri[0] for ri in rep))
i = 0
for b, c in rep:
    for _ in range(b):
        if a[i] < c:
            a[i] = c
            i += 1
        if i >= n:
            break
print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
bc = sorted([tuple(map(int, input().split())) for i in range(m)], key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
    while b:
        if a[i] < c and i < n:
            a[i] = c
            b -= 1
        else:
            break
        i += 1
print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
bc = sorted([tuple(map(int, input().split())) for i in range(m)], key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
    while b:
        if a[i] < c:
            a[i] = c
            b -= 1
        else:
            break
        i += 1
print(sum(a))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
cards = sorted(list(map(int, input().split())))
ope = [list(map(int, input().split())) for i in range(m)]
ope.sort(key=lambda x: x[1], reverse=True)
i, j, k = 0, 0, 0
while  j < m and cards[i] < ope[j][1]:
    cards[i] = ope[j][1]
    i += 1
    k += 1
    if k >= ope[j][0]:
        j += 1
        k = 0
print(sum(cards))
Problem p03077 (python)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(5)]
print(-(-n // min(a)) + 4)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
print(-(-n // min(a)) + 4)
Problem p03127 (python)

Fixed submission:
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]
ans = a[0]
for i in range(n - 1):
    ans = gcd(ans, a[i + 1])
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
n = int(input())
a = [int(i) for i in input().split()]
ans = a[0]
for i in range(n - 1):
    ans = gcd(ans, a[i + 1])
print(ans)
Problem p03137 (python)

Fixed submission:
n, m = map(int, input().split())
x = sorted([int(i) for i in input().split()])
diff_x = [x[i + 1] - x[i] for i in range(m - 1)]
diff_x.sort(reverse=True)
if n >= m:
    print(0)
else:
    print((x[m - 1] - x[0]) - sum(diff_x[0:n - 1]))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = sorted([int(i) for i in input().split()])
diff_x = [x[i + 1] - x[i] for i in range(m - 1)]
max_diff = []
if n >= m:
    print(0)
else:
    for _ in range(n - 1):
        max_diff_i = diff_x.index(max(diff_x))
        max_diff.append(max_diff_i)
        diff_x[max_diff_i] = -10**6
    max_diff.sort()

    move = x[max_diff[0]] - x[0]
    for i in range(n - 2):
        move += x[max_diff[i + 1]] - x[max_diff[i] + 1]
    move += x[m - 1] - x[max_diff[n - 2] + 1]
    print(move)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = sorted([int(i) for i in input().split()])
diff_x = [x[i + 1] - x[i] for i in range(m - 1)]
max_diff = []
if m == 1:
    print(0)
else:
    for _ in range(n - 1):
        max_diff_i = diff_x.index(max(diff_x))
        max_diff.append(max_diff_i)
        diff_x[max_diff_i] = -10**6
    max_diff.sort()

    move = x[max_diff[0]] - x[0]
    for i in range(n - 2):
        move += x[max_diff[i + 1]] - x[max_diff[i] + 1]
    move += x[m - 1] - x[max_diff[n - 2] + 1]
    print(move)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
x = sorted([int(i) for i in input().split()])
diff_x = [x[i + 1] - x[i] for i in range(m - 1)]
max_diff = []
for _ in range(n - 1):
    max_diff_i = diff_x.index(max(diff_x))
    max_diff.append(max_diff_i)
    diff_x[max_diff_i] = -1
max_diff.sort()

move = x[max_diff[0]] - x[0]
for i in range(n - 2):
    move += x[max_diff[i + 1]] - x[max_diff[i] + 1]
move += x[m - 1] - x[max_diff[n - 2] + 1]
print(move)
Problem p03250 (python)

Fixed submission:
a, b, c = map(int, input().split())
print(max(a, b, c)*9 + sum([a, b, c]))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print(max(a, b, c)*9 + sum(a, b, c))
Problem p03634 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
n = int(input())
to = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    to[a].append((b, c))
    to[b].append((a, c))

q, k = map(int, input().split())
dist_k = [0] + [-1] * n
dist_k[k] = 0

def dfs(v):
    for u, du in to[v]:
        if dist_k[u] != -1:
            continue
        dist_k[u] = dist_k[v] + du
        dfs(u)
dfs(k)
dist_xky = [0] * q
for i in range(q):
    x, y = map(int, input().split())
    dist_xky[i] = dist_k[x] + dist_k[y]
print(*dist_xky, sep='\n')

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

q, k = map(int, input().split())
dist_k = [0] + [-1] * n
dist_k[k] = 0

def dfs(v):
    for u, du in to[v]:
        if dist_k[u] != -1:
            continue
        dist_k[u] = dist_k[v] + du
        dfs(u)
dfs(k)
dist_xky = [0] * q
for i in range(q):
    x, y = map(int, input().split())
    dist_xky[i] = dist_k[x] + dist_k[y]
print(*dist_xky, sep='\n')
Problem p02623 (python)

Fixed submission:
import bisect

n,m,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
sum_a=[a[0]]
for i in range(len(a)-1):
    sum_a.append(sum_a[i]+a[i+1])
sum_b=[b[0]]
for i in range(len(b)-1):
    sum_b.append(sum_b[i]+b[i+1])

#現在のインデックス
idx_a=0
idx_b=0

while idx_a<n or idx_b<m:
    read=''
    #aの読める数
    oset_a=sum_a[idx_a-1] if idx_a>0 else 0
    can_cnt_a=bisect.bisect_right(sum_a,k+oset_a)
    #bの読める数
    oset_b=sum_b[idx_b-1] if idx_b>0 else 0
    can_cnt_b=bisect.bisect_right(sum_b,k+oset_b)
    read='a' if can_cnt_a-idx_a>can_cnt_b-idx_b else 'b'
    if idx_a==n:
        read='b'
    if idx_b==m:
        read='a'
    

    #読むほうをPOP
    k-=a[idx_a] if read=='a' else b[idx_b]
    #kを超えた場合ブレーク
    if k<0:
        break
    #カウントアップ
    if read=='a':
        idx_a+=1
    else:
        idx_b+=1
print(idx_a+idx_b)

Buggy submission (verdict: Runtime Error):
import bisect

n,m,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
sum_a=[a[0]]
for i in range(len(a)-1):
    sum_a.append(sum_a[i]+a[i+1])
sum_b=[b[0]]
for i in range(len(b)-1):
    sum_b.append(sum_b[i]+b[i+1])

#現在のインデックス
idx_a=0
idx_b=0

while idx_a<n or idx_b<m:
    read=''
    #aの読める数
    oset_a=sum_a[idx_a-1] if idx_a>0 else 0
    can_cnt_a=bisect.bisect_right(sum_a,k+oset_a)
    #bの読める数
    oset_b=sum_b[idx_b-1] if idx_b>0 else 0
    can_cnt_b=bisect.bisect_right(sum_b,k+oset_b)
    read='a' if can_cnt_a-idx_a>can_cnt_b-idx_b else 'b'
    

    #読むほうをPOP
    k-=a[idx_a] if read=='a' else b[idx_b]
    #kを超えた場合ブレーク
    if k<0:
        break
    #カウントアップ
    if read=='a':
        idx_a+=1
    else:
        idx_b+=1
print(idx_a+idx_b)

Buggy submission (verdict: Runtime Error):
import bisect

n,m,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
sum_a=[a[0]]
for i in range(len(a)-1):
    sum_a.append(sum_a[i]+a[i+1])
sum_b=[b[0]]
for i in range(len(b)-1):
    sum_b.append(sum_b[i]+b[i+1])

#現在のインデックス
idx_a=0
idx_b=0

while idx_a<n or idx_b<m:
    read=''
    #aの読める数
    oset_a=sum_a[idx_a-1] if idx_a>0 else 0
    can_cnt_a=bisect.bisect_right(sum_a,k+oset_a)
    #bの読める数
    oset_b=sum_b[idx_b-1] if idx_b>0 else 0
    can_cnt_b=bisect.bisect_right(sum_b,k+oset_b)
    read='a' if can_cnt_a-idx_a>=can_cnt_b-idx_b else 'b'
    

    #読むほうをPOP
    k-=a[idx_a] if read=='a' else b[idx_b]
    #kを超えた場合ブレーク
    if k<0:
        break
    #カウントアップ
    if read=='a':
        idx_a+=1
    else:
        idx_b+=1
print(idx_a+idx_b)