Buggy python submission (verdict: Runtime Error):
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b[y] > k - a[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)


Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m
for x in range(len(a_cum) + 1):
    if a_cum[x] > k:
        break
    while b[y] > k - a[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)


Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys
input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    for y in range(len(b_cum)):
        if a_cum[x] + b_cum[y] <= k:
            ans = max(ans, x + y)
        else:
            break

print(ans)


Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys
input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    for y in range(len(b_cum)):
        if a_cum[x] + b_cum[y] <= k:
            ans = max(ans, x + y)
        else:
            break

print(ans)


Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0

a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

for x in range(len(a_cum)):
    for y in range(len(b_cum)):
        if a_cum[x] + b_cum[y] <= k:
            ans = max(ans, x + y)
        else:
            break

print(ans)


Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0

a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

for x in range(len(a_cum)):
    for y in range(len(b_cum)):
        if a_cum[x] + b_cum[y] <= k:
            ans = max(ans, x + y)

print(ans)


Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)

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

n, m, k = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))

ans = 0
minutes = 0
while True:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) > 0 and len(b) > 0:
        if a[0] == b[0]:
            if ans + a[0] <= k:
                if a[1] >= b[1]:
                    minutes += 1
                    ans += b.popleft()
                else:
                    minutes += 1
                    ans += a.popleft()
            else:
                break
        elif a[0] > b[0]:
            if ans + b[0] <= k:
                minutes += 1
                ans += b.popleft()
            else:
                break
        else:
            if ans + a[0] <= k:
                minutes += 1
                ans += a.popleft()
            else:
                break

    elif len(b) == 0 and (a[0] + ans) <= k:
        minutes += 1
        ans += a.popleft()
    elif len(a) == 0 and (b[0] + ans) <= k:
        minutes += 1
        ans += b.popleft()
    else:
        break

print(minutes)
# print(ans)

Fixed submission:
import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)