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

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

for i in range(n + 1):
    if a[i] > k:
        break
    for j in range(m + 1):
        if a[i] + b[j] <= k:
            ans = max(ans, i + j)
        else:
            break
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

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + j)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = map(int, input().split())

a = [0] + list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = 0
cnta = 0
ans = 0


for i in range(n + 1):
    cnta += a[i]
    cnt = cnta
    if cnt > k:
        ans = max(ans, i - 1)
        break
    for j in range(m):
        cnt += b[j]
        if cnt > k:
            ans = max(ans, i + j)
            break
    else:
        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

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + 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(n + 1):
    cnt = sum(a[:i])
    if cnt > k:
        ans = max(ans, i - 1)
        break
    for j in range(m):
        cnt += b[j]
        if cnt > k:
            ans = max(ans, i + j)
            break
    else:
        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

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + 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(n + 1):
    for j in range(m + 1):
        s = sum(a[:i]) + sum(b[:j])
        if k >= sum(a[:i]) + sum(b[:j]):
            ans = max(ans, i + j)
        else:
            break

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

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + j)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
ac = 0
bc = 0

while cnt < k:
    if ac == len(A):
        cnt += B[bc]
        if cnt <= k:
            bc += 1
        else:
            break
    if bc == len(B):
        cnt += A[ac]
        if cnt <= k:
            ac += 1
        else:
            break
    if ac == len(A) and bc == len(B):
        break
    if A[ac] < B[ac]:
        cnt += A[ac]
        if cnt <= k:
            ac += 1
        else:
            break
    else:
        cnt += B[bc]
        if cnt <= k:
            bc += 1
        else:
            break

print(ac + bc)

Fixed submission:
n, m, k = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0

a = [0]
b = [0]

for i in range(n):
    a.append(a[i] + A[i])

for i in range(m):
    b.append(b[i] + B[i])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + j)
print(ans)