Buggy python submission (verdict: Runtime Error):
from  collections import deque
 
N, M, K =map(int, input().split())
A  = list(map(int, input().split()))
B  = list(map(int, input().split()))
 
A = deque(A)
B = deque(B)
 
def check(n, A_, B_):
  if len(A_) >= n and len(B_) >= n:
    if A_[n-1] > B_[n-1]:
      return 'B'
    elif A_[n-1] < B_[n-1]:
      return 'A'
    else:
      check(n+1, A_, B_)
  elif len(A_) < n and len(B_) <  n:
    return 'A'
  elif len(A_) < n:
    return 'B'
  else:
    return 'A'
  
#print(check(1, A, B))


ans = 0
while True:
  if A:
    a = A[0]
  else:
    a = 10**9+7
  if B:
    b = B[0]
  else:
    b = 10**9+7
  if min(a, b) > K:
    break
  elif len(A) == 0 and len(B) == 0:
    break
  else:
    j =check(1, A, B)
    if j ==  'A':
      K -= A.popleft()
      ans += 1
    else:
      K -= B.popleft()
      ans += 1
      
print(ans)

Fixed submission:
from bisect import *
 
N, M, K =map(int, input().split())
A  = list(map(int, input().split()))
B  = list(map(int, input().split()))

A_= [0]
for a in A:
  A_.append(A_[-1] + a)
#print(A_)

b_sum = 0
ans = 0
b_cnt = 0

while True:
  if b_sum > K:
    break
  else:
    k = K - b_sum
    ans = max(bisect_right(A_, k)-1 + b_cnt, ans)
    #print(bisect_right(A_, k)-1 + b_cnt, ans,  b_cnt)
    if b_cnt == M:
      break
    b_sum += B[b_cnt]
    b_cnt += 1
    

print(ans)

Buggy python submission (verdict: Runtime Error):
from  collections import deque
 
N, M, K =map(int, input().split())
A  = list(map(int, input().split()))
B  = list(map(int, input().split()))
 
A = deque(A)
B = deque(B)
 
def check(n, A_, B_):
  if len(A_) >= n and len(B_) >= n:
    if A_[n-1] > B_[n-1]:
      return 'B'
    elif A_[n-1] < B_[n-1]:
      return 'A'
    else:
      check(n+1, A_, B_)
  elif len(A_) < n and len(B_) <  n:
    return 'A'
  elif len(A_) < n:
    return 'B'
  else:
    return 'A'
  
#print(check(1, A, B))


ans = 0
while True:
  if A:
    a = A[0]
  else:
    a = 10**9+7
  if B:
    b = B[0]
  else:
    b = 10**9+7
  if min(a, b) > K:
    break
  else:
    j =check(1, A, B)
    if j ==  'A':
      K -= A.popleft()
      ans += 1
    else:
      K -= B.popleft()
      ans += 1
      
print(ans)

Fixed submission:
from bisect import *
 
N, M, K =map(int, input().split())
A  = list(map(int, input().split()))
B  = list(map(int, input().split()))

A_= [0]
for a in A:
  A_.append(A_[-1] + a)
#print(A_)

b_sum = 0
ans = 0
b_cnt = 0

while True:
  if b_sum > K:
    break
  else:
    k = K - b_sum
    ans = max(bisect_right(A_, k)-1 + b_cnt, ans)
    #print(bisect_right(A_, k)-1 + b_cnt, ans,  b_cnt)
    if b_cnt == M:
      break
    b_sum += B[b_cnt]
    b_cnt += 1
    

print(ans)

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

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

A = deque(A)
B = deque(B)

ans = 0
while True:
  a = A[0]
  b = B[0]
  if min(a, b) > K:
    break
  else:
    if a <  b:
      a = A.popleft()
      K -= a
      ans += 1
    else:
      b = B.popleft()
      K -= b
      ans += 1
  #print(ans,  K)
      
      
print(ans)

Fixed submission:
from bisect import *
 
N, M, K =map(int, input().split())
A  = list(map(int, input().split()))
B  = list(map(int, input().split()))

A_= [0]
for a in A:
  A_.append(A_[-1] + a)
#print(A_)

b_sum = 0
ans = 0
b_cnt = 0

while True:
  if b_sum > K:
    break
  else:
    k = K - b_sum
    ans = max(bisect_right(A_, k)-1 + b_cnt, ans)
    #print(bisect_right(A_, k)-1 + b_cnt, ans,  b_cnt)
    if b_cnt == M:
      break
    b_sum += B[b_cnt]
    b_cnt += 1
    

print(ans)