Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

for i in range(1, N):
    A[i] = A[i - 1] + A[i]
    if A[i] > K:
        A = A[:i]
        break
A = [0] + A

for i in range(1, M):
    B[i] = B[i - 1] + B[i]
    if B[i] > K:
        B = B[:i]
        break
B = [0] + B

A_length = len(A)
B_length = len(B)

for i in range(A_length):
    j = 0
    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    ans = max(ans, i + (j - 1))
print(ans)


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

for i in range(1, N):
    A[i] = A[i - 1] + A[i]
    if A[i] > K:
        A = A[:i]
        break
A = [0] + A
A = A[::-1]

for i in range(1, M):
    B[i] = B[i - 1] + B[i]
    if B[i] > K:
        B = B[:i]
        break
B = [0] + B

A_length = len(A)
B_length = len(B)

j = 0
for i in range(A_length):

    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    j -= 1

    ans = max(ans, A_length - (i + 1) + j)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

for i in range(1, N):
    A[i] = A[i - 1] + A[i]
    if A[i] > K:
        A = A[:i]
        break
A = [0] + A

for i in range(1, M):
    B[i] = B[i - 1] + B[i]
    if B[i] > K:
        B = B[:i]
        break
B = [0] + B

A_length = len(A)
B_length = len(B)

for i in range(A_length):
    j = 0
    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    ans = max(ans, i + (j - 1))
print(ans)


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

for i in range(1, N):
    A[i] = A[i - 1] + A[i]
    if A[i] > K:
        A = A[:i]
        break
A = [0] + A
A = A[::-1]

for i in range(1, M):
    B[i] = B[i - 1] + B[i]
    if B[i] > K:
        B = B[:i]
        break
B = [0] + B

A_length = len(A)
B_length = len(B)

j = 0
for i in range(A_length):

    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    j -= 1

    ans = max(ans, A_length - (i + 1) + j)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split())) + [10 ** 10]
B = list(map(int, input().split())) + [10 ** 10]

check = 0
i = 0
while (K >= (check + A[i])) & (i < N):
    check += A[i]
    i += 1

cnt = i

for ii in range(i):
    check2 = sum(A[:(i - ii)])
    j = 0
    while (K >= check2 + B[j]) & (j < M):
        check2 += B[j]
        cnt_j = j
        j += 1
    cnt = max(cnt, i - ii + cnt_j + 1)

print(cnt)


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

for i in range(1, N):
    A[i] = A[i - 1] + A[i]
    if A[i] > K:
        A = A[:i]
        break
A = [0] + A
A = A[::-1]

for i in range(1, M):
    B[i] = B[i - 1] + B[i]
    if B[i] > K:
        B = B[:i]
        break
B = [0] + B

A_length = len(A)
B_length = len(B)

j = 0
for i in range(A_length):

    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    j -= 1

    ans = max(ans, A_length - (i + 1) + j)
print(ans)