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

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


consumptions_A = [0]
for Ai in A:
    consumptions_A.append(consumptions_A + Ai)

consumptions_B = []
for Bi in B:
    consumptions_B.append(consumptions_B + Bi)

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

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

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


consumptions_A = [0]
for Ai in A:
    consumptions_A.append(consumptions_A + Ai)

consumptions_B = []
for Bi in B:
    consumptions_B.append(sum(B[:i]))

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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


consumptions_A = []
for i in range(len(A) + 1):
    consumptions_A.append(sum(A[:i]))

consumptions_B = []
for i in range(len(B) + 1):
    consumptions_B.append(sum(B[:i]))

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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


consumptions_A = []
for i in range(len(A) + 1):
    consumptions_A.append(sum(A[:i]))

consumptions_B = []
for i in range(len(B) + 1):
    consumptions_B.append(sum(B[:i]))

answer = 0
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    for j in range(len(consumptions_B)):
        consumption = consumptions_A[i] + consumptions_B[j]
        if (consumption > K): break
    
        num_books = i + j
        answer = max(answer, num_books)

print(answer)


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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


answer = 0
consumption_A = 0
for i in range(len(A) + 1):
    consumption_A += A[i - 1] if i >= 1 else 0
    if (consumption_A > K): break

    consumption_B = 0
    for j in range(len(B) + 1):
        consumption_B += B[j - 1] if j >= 1 else 0
        consumption = consumption_A + consumption_B
        if (consumption > K): break
    
        num_books = i + j
        answer = max(answer, num_books)

print(answer)


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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


answer = 0
for i in range(len(A) + 1):
    consumption_A = sum(A[:i])
    if (consumption_A > K): break

    for j in range(len(B) + 1):
        consumption_B = sum(B[:j])
        consumption = consumption_A + consumption_B
        if (consumption > K): break
    
        num_books = i + j
        answer = max(answer, num_books)

print(answer)


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

num_books = 0
remaining_time = K

A_ = ['A'] * len(A)
B_ = ['B'] * len(B)
AB_ = A_ + B_
# print(AB_)

import itertools
patterns = []
for v in itertools.permutations(AB_, len(AB_)):
    patterns.append(''.join(v))
patterns = list(set(patterns))
# print(patterns, len(patterns))

answer = 0
for pattern in patterns:
    remaining_time = K
    num_books = 0

    table = {
        'A': deque(A),
        'B': deque(B),
    }
    for book in pattern:
        if len(table[book]) <= 0: break

        remaining_time -= table[book].popleft()
        if remaining_time < 0: break
        
        num_books += 1
    # print(pattern, num_books)
    
    answer = max(answer, num_books)

print(answer)


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

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

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

num_books = 0
remaining_time = K

while True:
    consumption = 0

    if len(A) == 0 and len(B) == 0: break

    if len(A) == 0:
        consumption = B.popleft()
    elif len(B) == 0:
        consumption = A.popleft()
    elif A[0] == B[0]:
        if A[1] < B[1]:
            consumption = A.popleft()
        else: 
            consumption = B.popleft()
    elif A[0] < B[0]:
        consumption = A.popleft()
    else:
        consumption = B.popleft()
    # print(consumption)
    
    remaining_time -= consumption
    if remaining_time < 0: break

    num_books += 1

print(num_books)
    


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)

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

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

num_books = 0
remaining_time = K

while True:
    consumption = 0

    if len(A) == 0 and len(B) == 0: break

    if len(A) == 0:
        consumption = B.popleft()
    elif len(B) == 0:
        consumption = A.popleft()
    elif A[0] == B[0]:
        if A[1] < B[1]:
            consumption = A.popleft()
        elif: 
            consumption = B.popleft()
    elif A[0] < B[0]:
        consumption = A.popleft()
    else:
        consumption = B.popleft()
    # print(consumption)
    
    remaining_time -= consumption
    if remaining_time < 0: break

    num_books += 1

print(num_books)
    


Fixed submission:
from collections import deque

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


consumptions_A = [0]
for i in range(len(A)):
    consumptions_A.append(consumptions_A[i] + A[i])

consumptions_B = [0]
for i in range(len(B)):
    consumptions_B.append(consumptions_B[i] + B[i])

answer = 0
j = M
for i in range(len(consumptions_A)):
    if (consumptions_A[i] > K): break

    remaining_time = K - consumptions_A[i]
    while consumptions_B[j] > remaining_time:
        j -= 1
    
    num_books = i + j
    answer = max(answer, num_books)

print(answer)