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()))
 
totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iA = N
iB = 0
countMax = 0
while iA >= 0:
    if totalA[iA] + totalB[iB] > K:
        iA -= 1
    else:
        while totalA[iA] + totalB[iB] <= K:
          countMax = max(countMax,iA+iB)
          if iB == M:
            break
          iB += 1
    if iA == N and iB == M:
      break
          
print(countMax)
 

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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)

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()))

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[0]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[0]
    totalB.append(sumB)

iA = N
iB = 0
countMax = 0
while iA >= 0:
    if totalA[iA] + totalB[iB] > K:
        iA -= 1
    else:
        if iB < M:
            countMax = max(countMax, iA + iB)
            iB += 1
    elif iA == N and iB == M:
        countMax = max(countMax, iA + iB)
        break

print(countMax)



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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)

Buggy python submission (verdict: Runtime Error):
def checkWhichToRead(A, B):
    if len(A) == 0 or A[0] > B[0]:
        return 1
    elif len(B) == 0 or A[0] < B[0]:
        return 0
    else:
        return 2


def searchEqualCase(A, B, K, count):
    if K < 0:
        return count
    ACount = count
    BCount = count
    if len(A) > 0:
        ACount = searchEqualCase(A[1:], B, K - A[0], count + 1)
    if len(B) > 0:
        BCount = searchEqualCase(A, B[1:], K - B[0], count + 1)
    if ACount > BCount:
        return ACount
    else:
        return BCount


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

count = 0
while K >= 0:
    case = checkWhichToRead(A, B)
    if case == 0:
        K -= A[0]
        A = A[1:]
    elif case == 1:
        K -= B[0]
        B = B[1:]
    else:
        count = searchEqualCase(A, B, K, count)
        break
    count += 1
    if count == N + M:
        count += 1
        break

print(count - 1)



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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)

Buggy python submission (verdict: Runtime Error):
def checkWhichToRead(A, B):
    if len(A) == 0 or A[0] > B[0]:
        return 1
    elif len(B) == 0 or A[0] < B[0]:
        return 0
    else:
        return 2


def searchEqualCase(A, B, K, count):
    if K < 0:
        return count
    ACount = count
    BCount = count
    if len(A) > 0:
        ACount = checkWhichToRead(A[1:], B, K - A[0], count + 1)
    if len(B) > 0:
        BCount = checkWhichToRead(A, B[1:], K - B[0], count + 1)
    if ACount > BCount:
        return ACount
    else:
        return BCount


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

count = 0
while K >= 0:
    case = checkWhichToRead(A, B)
    if case == 0:
        K -= A[0]
        A = A[1:]
    elif case == 1:
        K -= B[0]
        B = B[1:]
    else:
        count = searchEqualCase(A, B, K, count)
        break
    count += 1
    if count == N + M:
        count += 1
        break

print(count - 1)




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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)

Buggy python submission (verdict: Runtime Error):
def checkWhichToRead(A, B, K, count):
    if K < 0:
        return count - 1
    ACount = count
    BCount = count
    if len(A) > 0:
        ACount = checkWhichToRead(A[1:], B, K - A[0], count + 1)
    if len(B) > 0:
        BCount = checkWhichToRead(A, B[1:], K - B[0], count + 1)
    if ACount > BCount:
        return ACount
    else:
        return BCount


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

print(checkWhichToRead(A, B, K, 0))



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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)