Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

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


a = [0]
b = [0]

for i in range(N):
    a.append(a[-1] + A[i])


for i in range(M):
    b.append(b[-1] + B[i])

ret = 0
for i in range(N+1):
    for j in range(M+1):
        if a[i] + b[j] <= K:
            ret = max(i+j, ret)
        else:
            break

print(ret)


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

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


a = [0]
b = [0]

for i in range(N):
    a.append(a[-1] + A[i])


for i in range(M):
    b.append(b[-1] + B[i])

ret = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1

    ret = max(i+j, ret)


print(ret)

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

from collections import deque


def book(A2, B2, t, cnt):
    if len(A2) == 0 and len(B2) == 0:
        L.append(cnt)
        return cnt
    elif t == K:
        L.append(cnt)
        return cnt
    elif t > K:
        L.append(cnt-1)
        return cnt - 1

    a_r = 0
    b_r = 0
    if len(A2) != 0:
        a = A2.popleft()
        a_r = book(A2, B2, t+a, cnt+1)
        
    if len(B2) != 0:
        b = B2.popleft()
        b_r = book(A2, B2, t+b, cnt+1)
    L.append(a_r)
    L.append(b_r)
    return max(a_r, b_r)




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

L = []

A = deque(A)
B = deque(B)

t = 0
ret = 0

ret = book(A, B, 0, 0)

print(max(L))


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

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


a = [0]
b = [0]

for i in range(N):
    a.append(a[-1] + A[i])


for i in range(M):
    b.append(b[-1] + B[i])

ret = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1

    ret = max(i+j, ret)


print(ret)

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

from collections import deque


def book(A, B, t, cnt):
    if len(A) == 0 and len(B) == 0:
        L.append(cnt)
        return cnt
    elif t == K:
        L.append(cnt)
        return cnt
    elif t > K:
        L.append(cnt-1)
        return cnt - 1

    a_r = 0
    b_r = 0
    if len(A) != 0:
        a = A.popleft()
        a_r = book(A, B, t+a, cnt+1)
        
    if len(B) != 0:
        b = B.popleft()
        b_r = book(A, B, t+b, cnt+1)
    L.append(a_r)
    L.append(b_r)
    return max(a_r, b_r)




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

L = []

A = deque(A)
B = deque(B)

t = 0
ret = 0

ret = book(A, B, 0, 0)

print(max(L))


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

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


a = [0]
b = [0]

for i in range(N):
    a.append(a[-1] + A[i])


for i in range(M):
    b.append(b[-1] + B[i])

ret = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1

    ret = max(i+j, ret)


print(ret)

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

from collections import deque


def book(A, B, t, cnt):
    if len(A) == 0 and len(B) == 0:
        return cnt
    elif t == K:
        return cnt
    elif t > K:
        return cnt - 1

    a_r = 0
    b_r = 0
    if len(A) != 0:
        a = A.popleft()
        a_r = book(A, B, t+a, cnt+1)
        
    if len(B) != 0:
        b = B.popleft()
        b_r = book(A, B, t+b, cnt+1)

    return max(a_r, b_r)




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

A = deque(A)
B = deque(B)

t = 0
ret = 0

ret = book(A, B, 0, 0)

print(ret)


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

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


a = [0]
b = [0]

for i in range(N):
    a.append(a[-1] + A[i])


for i in range(M):
    b.append(b[-1] + B[i])

ret = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1

    ret = max(i+j, ret)


print(ret)