Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000000)

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


def dfs(A_index, B_index, K, books):
    
    return_books = books
    return_booksA = books

    if N > A_index and K>=A[A_index]:
        return_books = dfs(A_index+1, B_index, K-A[A_index], books+1)
    if M > B_index and K>=B[B_index]:
        return_booksA = dfs(A_index, B_index+1, K-B[B_index], books+1)

    return max(return_books, return_booksA)

print(dfs(0, 0, K, 0))

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

def bins(A, B, K):
    A_it = list(it.accumulate(A))
    B_it = list(it.accumulate(B))

    A_index = bisect.bisect_right(A_it, K)
    B_index = bisect.bisect_right(B_it, K)

    A_it = [0]+A_it[:A_index]
    B_it = B_it[:B_index]

    maxs = 0
    count=0
    for i in A_it[::-1]:
        if K-i < 0:
            continue
        now = K-i
        B_index = bisect.bisect_right(B_it, now)

        maxs = max(maxs, B_index + max(A_index - count,0))
        count+=1

    return maxs

print(bins(A,B,K))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(2000000)

def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


def dfs(A_index, B_index, K, books):
    
    return_books = books
    return_booksA = books

    if N > A_index and K>=A[A_index]:
        return_books = dfs(A_index+1, B_index, K-A[A_index], books+1)
    if M > B_index and K>=B[B_index]:
        return_booksA = dfs(A_index, B_index+1, K-B[B_index], books+1)

    return max(return_books, return_booksA)

print(dfs(0, 0, K, 0))

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

def bins(A, B, K):
    A_it = list(it.accumulate(A))
    B_it = list(it.accumulate(B))

    A_index = bisect.bisect_right(A_it, K)
    B_index = bisect.bisect_right(B_it, K)

    A_it = [0]+A_it[:A_index]
    B_it = B_it[:B_index]

    maxs = 0
    count=0
    for i in A_it[::-1]:
        if K-i < 0:
            continue
        now = K-i
        B_index = bisect.bisect_right(B_it, now)

        maxs = max(maxs, B_index + max(A_index - count,0))
        count+=1

    return maxs

print(bins(A,B,K))

Buggy python submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


def dfs(A_index, B_index, K, books):
    
    return_books = books
    return_booksA = books

    if N > A_index and K>=A[A_index]:
        return_books = dfs(A_index+1, B_index, K-A[A_index], books+1)
    if M > B_index and K>=B[B_index]:
        return_booksA = dfs(A_index, B_index+1, K-B[B_index], books+1)

    return max(return_books, return_booksA)

print(dfs(0, 0, K, 0))

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

def bins(A, B, K):
    A_it = list(it.accumulate(A))
    B_it = list(it.accumulate(B))

    A_index = bisect.bisect_right(A_it, K)
    B_index = bisect.bisect_right(B_it, K)

    A_it = [0]+A_it[:A_index]
    B_it = B_it[:B_index]

    maxs = 0
    count=0
    for i in A_it[::-1]:
        if K-i < 0:
            continue
        now = K-i
        B_index = bisect.bisect_right(B_it, now)

        maxs = max(maxs, B_index + max(A_index - count,0))
        count+=1

    return maxs

print(bins(A,B,K))

Buggy python submission (verdict: Runtime Error):
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


A_index=0
B_index=0
books = 0

while True:
    temp = books
    if N <= A_index and M <= B_index:
        break
    
    elif N <= A_index  and K>=B[B_index]:
        books += 1
        K -= B[B_index]
        B_index += 1
        
    elif M <= B_index  and K>=A[A_index]:
        books += 1
        K -= A[A_index]
        A_index += 1
        
    elif A[A_index] > B[B_index] and K>=B[B_index]:
        books += 1
        K -= B[B_index]
        B_index += 1
        
    elif A[A_index] < B[B_index] and K>=A[A_index]:
        books += 1
        K -= A[A_index]
        A_index += 1
    if temp==books:
        break
print(books)

Fixed submission:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N, M, K = input_int()
A = many_int()
B = many_int()


import itertools as it
import bisect

def bins(A, B, K):
    A_it = list(it.accumulate(A))
    B_it = list(it.accumulate(B))

    A_index = bisect.bisect_right(A_it, K)
    B_index = bisect.bisect_right(B_it, K)

    A_it = [0]+A_it[:A_index]
    B_it = B_it[:B_index]

    maxs = 0
    count=0
    for i in A_it[::-1]:
        if K-i < 0:
            continue
        now = K-i
        B_index = bisect.bisect_right(B_it, now)

        maxs = max(maxs, B_index + max(A_index - count,0))
        count+=1

    return maxs

print(bins(A,B,K))