Buggy python submission (verdict: Runtime Error):
def main():
    N, M, K = map(int, input().split())
    bookA = list(map(int, input().split()))
    bookB = list(map(int, input().split()))
    Ai = 0
    Bi = 0
    C = 0

    while K > 0:
        if Ai - N == 0 and Bi - M == 0:
            break
        if Ai - N == 0:
            K = K - bookB[Bi]
            if K == 0:
                C = C + 1
                break
            elif K < 0:
                break
            C = C + 1
            Bi = Bi + 1
        elif Bi - M == 0:
            K = K - bookB[Bi]
            if K == 0:
                C = C + 1
                break
            elif K < 0:
                break
            C = C + 1
            Ai = Ai + 1
        else:
            if bookA[Ai] < bookB[Bi]:
                K = K - bookA[Ai]
                if K == 0:
                    C = C + 1
                    break
                elif K < 0:
                    break
                C = C + 1
                Ai = Ai + 1
            else:
                K = K - bookB[Bi]
                if K == 0:
                    C = C + 1
                    break
                elif K < 0:
                    break
                C = C + 1
                Bi = Bi + 1
    
    print(C)
    
    

main()

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

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])

    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)

    print(ans)
main()

Buggy python submission (verdict: Runtime Error):
def main():
    A, M, K = map(int, input().split())
    bookA = list(map(int, input().split()))
    bookB = list(map(int, input().split()))

    if len(bookA) != len(bookB):
        if len(bookA) > len(bookB):
            diff = len(bookA) - len(bookB)
            for i in range(diff + 1):
                bookB.append(1000000000)
            bookA.append(1000000000)
        else:
            diff = len(bookB) - len(bookA)
            for j in range(diff + 1):
                bookA.append(1000000000)
            bookB.append(1000000000)
    
    C = 0
    Ai = 0
    Bi = 0

    while K > -1:
        if bookA[Ai] < bookB[Bi]:
            K = K - bookA[Ai]
            if K == 0:
                C = C + 1
                break
            elif K < 1:
                break
            Ai = Ai + 1
            C = C + 1
        else:
            K = K - bookB[Bi]
            if K == 0:
                C = C + 1
                break
            elif K < 1:
                break
            Bi = Bi + 1
            C = C + 1
    print(C)
    

main()

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

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])

    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i + j)

    print(ans)
main()