Buggy python submission (verdict: Time Limit Exceeded):
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
a=0
b=0
inter = 0
n = max(A, B)
for i in range(n):
  if len(List_A)==0 and len(List_B)==0:
    break
  elif len(List_A)==0 and len(List_B)!=0:
    inter+=List_B.pop(0)
    if K < inter:
      break
    res +=1
  elif len(List_A) !=0 and len(List_B)==0:
    inter+=List_A.pop(0)
    if K < inter:
      break
    res +=1
  else:
    a = List_A.pop(0)
    b = List_B.pop(0)
    inter = inter + a+b
    if K < inter: 
      inter = inter -a
      if K < inter:
        inter = inter +a-b
        if K < inter:
          break
        else:
          res +=1
      else:
        res +=1
    else:
      res +=2
print(res)

Fixed submission:
A,B,K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
SumListB=[]
SumListB.append(0)
res =0
a=0
for i in range(A):
  SumListA.append(SumListA[i]+List_A[i])
for i in range(B):
  SumListB.append(SumListB[i]+List_B[i])

j=B
for i in range(A+1):
  if SumListA[i] > K:
    break
  while K-SumListA[i] < SumListB[j]:
    j += -1
  res = max(i+j,res)
print(res)

Buggy python submission (verdict: Runtime Error):
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
inter = 0
n = A+B
for i in range(n):
  if len(List_A)==0:
    inter+=List_B.pop(0)
  elif len(List_B)==0:
    inter+=List_A.pop(0)
  else:
    if List_A[0]>List_B[0]:
      inter+=List_B.pop(0)
    elif List_A[0] < List_B[0]:
      inter+=List_A.pop(0)
    else:
      if List_B[1] > List_A[1]:
        inter+=List_A.pop(0)
      elif List_A[1] > List_B[1]:
        inter+=List_B.pop(0)
      else:
        if len(List_A) > len(List_B):
          inter = inter + List_A.pop(0)
        else:
          inter = inter + List_B.pop(0)
  if K < inter:
    break
  else:
    res +=1
print(res)

Fixed submission:
A,B,K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
SumListB=[]
SumListB.append(0)
res =0
a=0
for i in range(A):
  SumListA.append(SumListA[i]+List_A[i])
for i in range(B):
  SumListB.append(SumListB[i]+List_B[i])

j=B
for i in range(A+1):
  if SumListA[i] > K:
    break
  while K-SumListA[i] < SumListB[j]:
    j += -1
  res = max(i+j,res)
print(res)

Buggy python submission (verdict: Runtime Error):
A,B, K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
res = 0
a=0
b=0
inter = []
inter2 = 0
n = A+B
for i in range(n):
  if a ==A and b !=B:
    inter.append(List_B[b])
    b +=1
  elif a !=A and b ==B:
    inter.append(List_A[a])
    a +=1
  else:
    if List_A[a]>List_B[b]:
      inter.append(List_B[b])
      b +=1
    elif List_A[a] < List_B[b]:
      inter.append(List_A[a])
      a +=1
    else:
      k = min(A-a, B-b)
      for j in range(1,k):
        if List_B[b+j] > List_A[a+j]:
          inter.append(List_A[a])
          a +=1
          break
        elif List_A[a+j] > List_B[b+j]:
          inter.append(List_B[b])
          b +=1
          break
        else:
          if j == k-1:
            if B-b > A-a:
              inter.append(List_A[a])
              a +=1
              break
            elif A-a > B-b:
              inter.append(List_B[b])
              b += 1
              break
          else:
            pass
for i in range(n):
  inter2 += inter[i]
  if K < inter2:
    break
  else:
    res +=1
print(res)

Fixed submission:
A,B,K=map(int,input().split())
List_A = list(map(int, input().split()))
List_B = list(map(int, input().split()))
SumListA=[]
SumListA.append(0)
SumListB=[]
SumListB.append(0)
res =0
a=0
for i in range(A):
  SumListA.append(SumListA[i]+List_A[i])
for i in range(B):
  SumListB.append(SumListB[i]+List_B[i])

j=B
for i in range(A+1):
  if SumListA[i] > K:
    break
  while K-SumListA[i] < SumListB[j]:
    j += -1
  res = max(i+j,res)
print(res)