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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = count
    else:
        count_a = count
    if len(desk_b) != 0:
        # book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_b = count
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        # book_a = desk_a.popleft()
        # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = 0
    else:
        count_a = count
    if len(desk_b) != 0:
        # book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_a = 0
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        # book_a = desk_a.popleft()
        # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = 0
    else:
        count_a = count
    if len(desk_b) != 0:
        # book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_a = 0
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        # count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
        count_a = 0
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        # count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
        count_a = 0
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    # if len(desk_b) != 0:
    #     book_b = desk_b.popleft()
    #     count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    # else:
    #     count_b = count
    # return max(count_a, count_b)
    return count_a

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    # if len(desk_b) != 0:
    #     book_b = desk_b.popleft()
    #     count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    # else:
    #     count_b = count
    # return max(count_a, count_b)
    return count_a

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=None)
desk_b = deque([int(n) for n in input().split()], maxlen=None)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)

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

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()])
desk_b = deque([int(n) for n in input().split()])

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


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

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)