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

Fixed submission:
k,s=map(int,input().split())
x=0
m=min(s+1,k+1)
for a in range(m):
  for b in range(m):
    if a+b>s or a+b<s-k:
      continue
    x+=1
print(x)

Buggy submission (verdict: Runtime Error):
k,s=map(int,input().split())
x=0
for a in range(k+1):
  if a>s:
    break
  for b in range(k+1):
    if a+b>s:
      break
    for c in range(k+1):
      if a+b+c=s:
        x+=1
print(x)
Problem p03986 (python)

Fixed submission:
x=input()
t=0;s=0
for i in range(len(x)-1,-1,-1):
  if x[i]=='T':
    t+=1
  else:
    if t>0:
      t-=1
    else:
      s+=1
print(s+t)

Buggy submission (verdict: Runtime Error):
x=input()
t=0
for i in range(len(x)-1,-1,-1):
  if x[i]=='T':
    t+=1
  else:
    if t>0:
      t-=1
    else:
      s+=1
print(s+t)
Problem p02595 (python)

Fixed submission:
import math
n, d = list(map(int, input().split()))
count = 0
for _ in range(n):
  x, y = list(map(int, input().split()))
  if math.sqrt(x**2 + y**2) <= d:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
import math
n, d = list(map(int, input().split()))
count = 0
for _ in range(n):
  x, y = list(map(int, input().split()))
  if math.sqrt(x**2 + y**2) >= d
  count += 1
print(count)
Problem p02773 (python)

Fixed submission:
N = int(input())
l = []
for _ in range(N):
    l.append(input())

from collections import Counter

co = Counter(l).most_common()
l = [co[0][0]]

for n in range(len(co)-1):
    if co[n+1][1] == co[n][1]:
        l.append(co[n+1][0])
    else:
        break
l.sort()

for n in range(len(l)):
    print(l[n])

Buggy submission (verdict: Runtime Error):
N = int(input())
l = []
for _ in range(N):
    l.append(input())

from collections import Counter

co = Counter(l).most_common()
l = [co[0][0]]

for n in range(N):
    if co[n+1][1] == co[n][1]:
        l.append(co[n+1][0])
    else:
        break
l.sort()

for n in range(len(l)):
    print(l[n])
Problem p02598 (python)

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

def isOk(x):
    cnt = 0
    for a in A:
        cnt += (a - 1) // x
    return cnt <= K

ok = max(A)
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

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

def isOk(x):
    cnt = 0
    for a in A:
        cnt += a // x
    return cnt <= K

ok = max(A)
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

assert isOk(ok), (ok, isOk(ok))

print(ok)

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

def isOk(x):
    cnt = 0
    for a in A:
        cnt += a // x
    return cnt <= K

ok = max(A)
ng = 0
for _ in range(50):
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)
Problem p02679 (python)

Fixed submission:
from collections import Counter
import sys
input = sys.stdin.buffer.readline

N = int(input())

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def make(a, b):
    if a == b == 0:
        return (0, 0, 0)
    if a == 0:
        return (0, 1, 0)
    if b == 0:
        return (1, 0, 0)

    s = 1 if a * b > 0 else -1
    a, b = abs(a), abs(b)

    g = gcd(a, b)
    a //= g
    b //= g

    return (a, b, s)

ABS = Counter([make(*map(int, input().split())) for _ in range(N)])

ans = 1
MOD = 10**9 + 7

for a, b, s in list(ABS.keys()):
    if a == b == 0:
        continue
    p = ABS[(a, b, s)]
    n = ABS[(b, a, -s)]

    ABS[(a, b, s)] = 0
    ABS[(b, a, -s)] = 0

    cnt = pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans = (ans * cnt) % MOD

ans += ABS[(0, 0, 0)]

print((ans - 1) % MOD)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
input = sys.stdin.buffer.readline

N = int(input())

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def make(a, b):
    s = 1 if a * b >= 0 else -1
    a, b = abs(a), abs(b)

    g = gcd(a, b)
    a //= g
    b //= g

    return (a, b, s)

ABS = Counter([make(*map(int, input().split())) for _ in range(N)])
K = list(ABS.keys())

ans = 1
MOD = 10**9 + 7

for a, b, s in K:
    p = ABS[(a, b, s)]
    n = ABS[(b, a, -s)]

    ABS[(a, b, s)] = 0
    ABS[(b, a, -s)] = 0

    cnt = pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans = (ans * cnt) % MOD

print((ans - 1) % MOD)

Buggy submission (verdict: Runtime Error):
from collections import Counter
import sys
input = sys.stdin.buffer.readline

N = int(input())

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def make(a, b):
    s = 1 if a * b >= 0 else -1
    a, b = abs(a), abs(b)

    g = gcd(a, b)
    a //= g
    b //= g

    return (a, b, s)

ABS = Counter([make(*map(int, input().split())) for _ in range(N)])

ans = 1
MOD = 10**9 + 7

for a, b, s in list(ABS.keys()):
    p = ABS[(a, b, s)]
    n = ABS[(b, a, -s)]

    ABS[(a, b, s)] = 0
    ABS[(b, a, -s)] = 0

    cnt = pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans = (ans * cnt) % MOD

print((ans - 1) % MOD)
Problem p02726 (python)

Fixed submission:
N, X, Y = map(int, input().split())

def dist(fr, to):
    return min(
        to - fr,
        abs(to - Y) + 1 + abs(fr - X),
        abs(fr - Y) + 1 + abs(to - X)
    )

cnt = [0] * N

ans = 0
for fr in range(1, N + 1):
    for to in range(fr + 1, N + 1):
        cnt[dist(fr, to)] += 1

print(*(cnt[1:]), sep='\n')

Buggy submission (verdict: Runtime Error):
a = b
Problem p02736 (python)

Fixed submission:
N = int(input())
A = list(map(lambda a: int(a) - 1, input()))

prd = 1
if all(a % 2 == 0 for a in A):
    prd = 2
    A = [a // 2 for a in A]

ans = 0
for i in range(N):
    if (N - 1) & i == i:
        ans ^= A[i] % 2

print(prd * ans)

Buggy submission (verdict: Runtime Error):
import random
print(random.randint() % 2)

Buggy submission (verdict: Runtime Error):
import random
print(random.randint() % 2)
Problem p02851 (python)

Fixed submission:
from collections import defaultdict, deque

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

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

cnt = defaultdict(int)
que = deque([])
ans = 0

for i, c in enumerate(cumA):
    while que and que[0][0] <= i - K:
        cnt[que.popleft()[1]] -= 1
    diff = (i - c) % K
    ans += cnt[diff]
    cnt[diff] += 1
    que.append((i, diff))
print(ans)

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
INF = 10**18

cnt = Counter()
cnt[0] = 1
que = deque([-INF] * (K - 1) + [0])
sumR = 0
ans = 0
for right, a in enumerate(A, start=1):
    cnt[que.popleft()] -= 1
    sumR = (a + sumR) % K
    D = (sumR - right) % K
    ans += cnt[D]
    cnt[D] += 1
    que.append(D)
print(ans)
Problem p02862 (python)

Fixed submission:
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

    def f(self, p, q):
        return self.fact[p + q] * self.factInv[p] * self.factInv[q] % MOD


X, Y = map(int, input().split())
MOD = 10**9 + 7

if (X + Y) % 3 != 0:
    print(0)
    exit()

time = (X + Y) // 3
ans = 0
comb = Combination(time + 10)

for y in range(time + 1):
    x = time - y

    if X == x * 2 + y and Y == y * 2 + x:
        ans += comb.f(x, y)
        ans %= MOD

print(ans % MOD)

Buggy submission (verdict: Runtime Error):
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

    def f(self, p, q):
        return self.fact[p + q] * self.factInv[p] * self.factInv[q] % MOD


X, Y = map(int, input().split())
MOD = 10**9 + 7

if (X + Y) % 3 != 0:
    print(0)
    exit()

time = (X + Y) // 3
ans = 0
comb = Combination(time + 10)

x = (2 * X - Y) // 3
y = time - x

print(comb.f(x, y) % MOD)
Problem p02925 (python)

Fixed submission:
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')


def sol():
    N = int(input())
    A = [deque()] + [deque(map(int, input().split())) for _ in range(N)]

    days = [0] * (N + 1)
    now = [0] * (N + 1)

    que = deque([i + 1 for i in range(N)])

    while que:
        i = que.popleft()
        if not A[i]:
            continue

        a = A[i].popleft()
        if now[a] == i:
            days[a] = days[i] = max(days[a], days[i]) + 1
            que.append(i)
            que.append(a)
            now[a] = now[i] = 0
        else:
            now[i] = a

    for i in range(1, N + 1):
        if A[i]:
            print(-1)
            return
    print(max(days))


sol()

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

N = int(input())
A = deque([deque(map(lambda a: (i, int(a) - 1), input().split())) for i in range(N)])

canBattle = defaultdict(lambda: False)
D = [0] * N

while True:
    isChanged = False
    i, a = A.popleft()
    if not a:
        continue
    A.append((i, a))
    j = a[0]
    canBattle[(i, j)] = True

    if canBattle[(j, i)]:
        isChanged = True
        A[i].popleft()
        A[j].popleft()
        d = max(D[i], D[j])
        D[i], D[j] = d + 1, d + 1
    if all(len(a) == 0 for a in A):
        print(max(D))
        exit()
    if not isChanged:
        break

print(-1)
Problem p03018 (python)

Fixed submission:
S = input()
S = S.replace('BC', 'D').replace('B', ' ').replace('C', ' ').split()

ans = 0
for s in S:
    leftA = 0
    for i, t in enumerate(s[:: -1]):
        if t == 'A':
            ans += max(0, i - leftA)
            leftA += 1

print(ans)

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

ans = 0
i = 0

while i < len(s) :
    if s[i] == 'A' :
        if s[i+1] == 'B' and s[i+2] == 'C' : # 置換可能
            j = 1
            for j in range(1,i+1) :
                if not s[i-j] == 'A' : # 後方置換
                    break
            k = 0
            for k in range(0,len(s)) :
                ans += j - 1 + k
                if not s[i+k] == 'A' :
                    break
            i += k + 3
    i += 1

print(ans + 1)
Problem p03033 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

N, Q = map(int, input().split())
INF = float('inf')

events = []
for i in range(N):
    S, T, X = map(int, input().split())
    events.append((S - X, 0, X))
    events.append((T - X, 1, X))

for _ in range(Q):
    events.append((int(input()), 2, 0))

events.sort()

cnt = defaultdict(int)
cnt[INF] += 1
que = [INF]

for t, flag, x in events:
    if flag == 0:
        if cnt[x] == 0:
            heappush(que, x)
        cnt[x] += 1
    elif flag == 1:
        cnt[x] -= 1
    else:
        while cnt[que[0]] == 0:
            heappop(que)
        print(que[0] if que[0] != INF else -1)

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

D = [0]*Q
Input = []
length = [-1]*Q

for i in range(N):
    Input.append(list(map(int,input().split())))

# 距離順でソート
dist = lambda A : A[2]
Input.sort(key=dist)

for i in range(Q):
    D[i] = [i,int(input())]

# 出発時刻でソート
time = lambda A : A[1]
D.sort(key=time)

# i番目の人の座標を計算
skip = 0
for start in D:
    for j in range(N-skip):
        if(Input[j][1] <= start[1]): # 工事終了時刻 <= 出発時刻
            Input.pop(j)
            skip += 1
            continue

        stopTime = Input[j][2] + start[1] # 出発時刻 + 距離/速度

        if(stopTime >= Input[j][0] - 0.5 and stopTime <= Input[j][1] - 0.5): # 工事期間内
            length[start[0]] = Input[j][2]
            break

for i in range(Q):
    print(length[i])

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

D = [0]*Q
Input = []
length = [-1]*Q

for i in range(N):
    Input.append(list(map(int,input().split())))

# 距離順でソート
dist = lambda A : A[2]
Input.sort(key=dist)

for i in range(Q):
    D[i] = [i,int(input())]

# 出発時刻でソート
time = lambda A : A[1]
D.sort(key=time)

# i番目の人の座標を計算
skip = 0
for start in D:
    for j in range(N):
        if(Input[j][1] <= start[1]): # 工事終了時刻 <= 出発時刻
            Input.pop(j)
            continue

        stopTime = Input[j][2] + start[1] # 出発時刻 + 距離/速度

        if(stopTime >= Input[j][0] - 0.5 and stopTime <= Input[j][1] - 0.5): # 工事期間内
            length[start[0]] = Input[j][2]
            break

for i in range(Q):
    print(length[i])
Problem p03038 (python)

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

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

A.sort()

conv = []

for i in range(M) :
    B , C = map(int,input().split())
    conv.append([B,C])

sec = lambda A : A[1]
conv.sort(key=sec,reverse=True)

change = []
add = 0

# 大きいものからN個とる
for c in conv :
    for i in range(c[0]) :
        change.append(c[1])
        add += 1

    if(add >= N) :
        break

for i in range(min(N,len(change))) :
    if A[i] >= change[i] :
        break
    A[i] = change[i]

print(int(sum(A)))

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

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

A.sort()

conv = []

for i in range(M) :
    B , C = map(int,input().split())
    conv.append([B,C])

sec = lambda A : A[1]
conv.sort(key=sec,reverse=True)

change = []
add = 0

# 大きいものからN個とる
for c in conv :
    for i in range(c[0]) :
        change.append(c[1])
        add += 1

    if(add >= N) :
        break

for i in range(len(change)) :
    if A[i] >= change[i] :
        break
    A[i] = change[i]

print(int(sum(A)))
Problem p03041 (python)

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

ans = S[:K-1] + S[K-1].replace('A','a').replace('B','b').replace('C','c') + S[K:]

print(ans)

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

if S[K] == 'A' :
    S[K] = 'a'
if S[K] == 'B' :
    S[K] = 'b'
if S[K] == 'C' :
    S[K] = 'c'

print(S)
Problem p03055 (python)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.buffer.readline

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

for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

def calcDist(fr):
    minDist = [10**18] * N
    que = deque([(fr, 0)])

    while que:
        now, dist = que.pop()

        if minDist[now] < dist:
            continue
        minDist[now] = dist

        for to in edges[now]:
            if minDist[to] > dist + 1:
                minDist[to] = dist + 1
                que.append((to, dist + 1))

    return minDist

D0 = calcDist(0)
R = max(calcDist(D0.index(max(D0)))) + 1

print('Second' if R % 3 == 2 else 'First')

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
input = sys.stdin.buffer.readline

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

for _ in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

def calcDist(fr):
    minDist = [10**18] * N
    que = deque([(fr, 0)])

    while que:
        now, dist = que.pop()

        if minDist[now] < dist:
            continue
        minDist[now] = dist

        for to in edges[now]:
            if minDist[to] > dist + 1:
                minDist[to] = dist + 1
                que.append((to, dist + 1))

    return minDist

D0 = calcDist(0)
R = max(calcDist(D0.index(max(D0)))) + 1

canFirstWin = [False] * (R + 1)
canFirstWin[1] = True
canFirstWin[2] = False

for i in range(3, R + 1):
    canFirstWin[i] = not(canFirstWin[i - 1] and canFirstWin[i - 2])

print('First' if canFirstWin[R] else 'Second')
Problem p03209 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

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

if X < N :
    print(0)
else :
    pat = [0] * (N + 1)  # パティ数
    ban = [0] * (N + 1)  # バンズ数
    pat[0] = 1
    for i in range(1, N + 1) :
        pat[i] = 2 * pat[i - 1] + 1
        ban[i] = 2 * ban[i - 1] + 2
    def sol(level, height) :
        if height <= 0 :
            return 0
        if level == 0 :
            return 1
        if height <= 1 :
            return 0
        if height < pat[level - 1] + ban[level - 1] :
            return sol(level - 1, height - 1)
        if height == pat[level - 1] + ban[level - 1] + 1 :
            return pat[level - 1]
        if height == pat[level - 1] + ban[level - 1] + 2 :
            return pat[level - 1] + 1
        return pat[level - 1] + 1 + sol(level - 1, height - (pat[level - 1] + ban[level - 1] + 2))

    ans = sol(N, X)
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 7)

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

if X < N :
    print(0)
else :
    burger = [-1] * (N + 1)
    def makeBurger(level) :
        if level == 0 :
            return '1'
        if burger[level] == -1 :
            middle = makeBurger(level - 1)
            burger[level - 1] = middle
        else :
            middle = burger[level - 1]
        return '0' + middle + '1' + middle + '0'
    ans = makeBurger(N)[:X]
    print(ans.count('1'))

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

if X < N :
    print(0)
else :
    burger = [-1] * (N + 1)
    def makeBurger(level) :
        if level == 0 :
            return '1'
        if burger[level] == -1 :
            middle = makeBurger(level - 1)
            burger[level - 1] = middle
        else :
            middle = burger[level - 1]
        return '0' + middle + '1' + middle + '0'
    ans = makeBurger(N)[:X]
    print(ans.count('1'))
Problem p03426 (python)

Fixed submission:
H, W, D = map(int, input().split())
A = [tuple(map(int, input().split())) for _ in range(H)]

aToHW = {}
for h in range(H):
    for w, a in enumerate(A[h]):
        aToHW[a] = (h, w)

cnt = [-1] * (H * W + 1)
for start in range(1, H * W + 1)[:: -1]:
    c = 0
    for now in range(start, H * W + 1, D):
        if now + D > H * W:
            break
        if cnt[now] >= 0:
            c += cnt[now]
            break

        nH, nW = aToHW[now]
        tH, tW = aToHW[now + D]
        c += abs(nH - tH) + abs(nW - tW)
    cnt[start] = c

Q = int(input())
ans = []
for _ in range(Q):
    L, R = map(int, input().split())
    ans.append(cnt[L] - cnt[R])

print(*ans, sep='\n')

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

H, W, D = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(H)]
aToHW = {}
for h, row in enumerate(A):
    for w, a in enumerate(row):
        aToHW[a] = (h, w)

Q = int(input())

@lru_cache(maxsize=None)
def search(now):
    if not now + D in aToHW:
        return 0

    l, r = aToHW[now], aToHW[now + D]
    return abs(l[0] - r[0]) + abs(l[1] - r[1]) + search(now + D)

ans = []
for _ in range(Q):
    l, r = map(int, input().split())

    ans.append(search(l) - search(r))

print(*ans, sep='\n')
Problem p03822 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [0, 0] + [int(input()) for _ in range(N - 1)]

child = [[] for _ in range(N + 1)]
for i, a in enumerate(A):
    child[a].append(i)

def depth(i):
    if not child[i]:
        return 0

    childDepth = [depth(to) for to in child[i]]
    childDepth.sort(reverse=True)
    ret = 0
    for j, d in enumerate(childDepth, start=1):
        ret = max(j + d, ret)
    return ret

ans = depth(1)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0, 0] + [int(input()) for _ in range(N - 1)]

child = [[] for _ in range(N + 1)]
for i, a in enumerate(A):
    child[a].append(i)

def depth(i):
    if not child[i]:
        return 0

    childDepth = [depth(to) for to in child[i]]
    childDepth.sort(reverse=True)
    ret = 0
    for j, d in enumerate(childDepth, start=1):
        ret = max(j + d, ret)
    return ret

ans = depth(1)
print(ans)
Problem p02623 (python)

Fixed submission:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m,k = readInts()
A = [0] + list(accumulate(readInts()))
B = list(accumulate(readInts()))
ans = 0
import bisect
#print(B)
for i in range(len(A)):
    if A[i] > k:
        continue
    x = bisect.bisect_left(B,k - A[i] + 1)
    #print(x,)
    ans = max(ans,x+i)
print(ans)

Buggy submission (verdict: Runtime Error):
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n,m,k = readInts()
A = readInts()
B = readInts()
A = [0] + list(accumulate(A))
B = list(accumulate(B))
ans = 0
for i in range(len(A)):
    res = A[i]
    print('res:',A[i])
    print(B)
    r = bisect.bisect_right(B, k-res+1)
    print(r,'\n - - -\n')
    #print(i,r)
    if res <= k:
        ans = max(ans , i+r)
print(ans)