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

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

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

for j in range(len(a_accum)):
  for i in range(len(b_accum)):
    t = a_accum[-(j+1)] + b_accum[-(i+1)]
    candi = (n-j) + (m-i)
    if ans >= candi:
      break
    if t <= k:
      ans = candi
      break

print(ans)

Fixed submission:
from itertools import accumulate

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

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    ans = i + j

print(ans)

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

N, M, K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))
# N, M, K = map(int, "3 4 1000000000".split())
# A = deque(map(int, "600000000 90 120".split()))
# B = deque(map(int, "800000000 150 80 150".split()))

result = 0

while (A != deque() and K >= A[0]) or (B != deque() and K >= B[0]):
    a, b = 0, 0
    na, nb = 0, 0
    for i in A:
        if a+i <= K:
            a += i
            na += 1
        else:
            break
    for i in B:
        if b+i <= K:
            b += i
            nb += 1
        else:
            break


    if na > nb:
        result += 1
        na -= 1
        K -= A.popleft()
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.popleft()
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.popleft()
        else:
            nb -= 1
            K -= B.popleft()
print(result)


Fixed submission:
from itertools import accumulate

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

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    ans = i + j

print(ans)

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

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

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in range(len(A)):
    if a+A[i] <= K:
        a += A[i]
        na += 1
    else:
        break
for i in range(len(B)):
    if b+B[i] <= K:
        b += B[i]
        nb += 1
    else:
        break

while A != deque() and K >= A[0]:
    if na > nb:
        result += 1
        na -= 1
        K -= A.popleft()
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.popleft()

while B != deque() and K >= B[0]:
    if na < nb:
        result += 1
        nb -= 1
        K -= B.popleft()
    elif na == nb:
        result += 1
        if A[0] > B[0]:
            nb -= 1
            K -= B.popleft()

print(result)


Fixed submission:
from itertools import accumulate

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

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    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()))

result = 0

a, b = 0, 0
na, nb = 0, 0
for i in range(len(A)):
    if a+A[i] <= K:
        a += A[i]
        na += 1
    else:
        break
for i in range(len(B)):
    if b+B[i] <= K:
        b += B[i]
        nb += 1
    else:
        break

while A != [] and K >= A[0] or B != [] and K >= B[0]:
    if na > nb:
        result += 1
        na -= 1
        K -= A.pop(0)
    elif na < nb:
        result += 1
        nb -= 1
        K -= B.pop(0)
    elif na == nb:
        result += 1
        if A[0] <= B[0]:
            na -= 1
            K -= A.pop(0)
        else:
            nb -= 1
            K -= B.pop(0)


print(result)


Fixed submission:
from itertools import accumulate

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

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    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()))

result = 0

while A != [] and K >= A[0] or B != [] and K >= B[0]:
    a, b = 0, 0
    na, nb = 0, 0
    for i in range(len(A)):
        if a+A[i] <= K:
            a += A[i]
            na += 1
        else:
            break
    for i in range(len(B)):
        if b+B[i] <= K:
            b += B[i]
            nb += 1
        else:
            break
    if na > nb:
        K -= A.pop(0)
        result += 1
    elif na < nb:
        K -= B.pop(0)
        result += 1
    elif na == nb:
        if A[0] <= B[0]:
            K -= A.pop(0)
        else:
            K -= B.pop(0)
        result += 1

print(result)


Fixed submission:
from itertools import accumulate

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

a_accum = [0] + list(accumulate(a))
b_accum = [0] + list(accumulate(b))

j = m
for i in range(n+1):
  while k < a_accum[i] + b_accum[j] and j >= 1:
    j -= 1
  if k >= a_accum[i] + b_accum[j] and ans < i + j:
    ans = i + j

print(ans)