Buggy python submission (verdict: Runtime Error):
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)

# def func(arr, b):
# 	return([i-b for i in arr])

# def f(i, j, t):
# 	if t >=k:
# 		return(i+j)
# 	return(max(f(i+1, j, t+a_[i+1]), f(i, j+1, t+b_[j+1])))



def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	dic = {}
	def f(i, j, t):
		# print(i, j, t, "******")
		key = (i, j, t)
		if key in dic:
			return(dic[key])
		if t == k:
			# print(i, j, t, "11111")
			dic[key] = i+j
			return(dic[key])
		if t > k:
			# print(i, j, t, "22222")
			dic[key] = i+j-1
			return(dic[key])
		if i ==a and j ==b:
			# print(i, j, t, "0"*5)
			dic[key] = i+j
			return(dic[key])
		if i == a:
			dic[key] = f(i, j+1, t + b_[j])
			return(dic[key])
		if j == b:
			dic[key] = f(i+1, j, t + a_[i])
			return(dic[key])
		

		x = f(i+1, j, t+a_[i]) if i < a else 0#f(i+1, j, t)
		y = f(i, j+1, t+b_[j]) if j < b else 0#f(i, j+1, t)
		dic[key] = max(x, y)
		return(dic[key])
	# for i in range(1, a): a_[i] += a_[i-1]
	# for i in range(1, b): b_[i] += b_[i-1]
	# ans = 0
	# while k > 0:
	# 	inda = bisect(a_, k); indb = bisect(b_, k)
	# 	# print(k, inda, indb, a_[inda-1], b_[indb-1])
	# 	if inda > indb:
	# 		k -= a_[inda-1];
	# 		ans += inda
	# 		a_ = func(a_[inda:], a_[inda-1])
	# 	elif inda == indb:
	# 		if a_[inda-1] < b_[indb-1]:
	# 			k -= a_[inda-1];
	# 			ans += inda
	# 			a_ = func(a_[inda:], a_[inda-1])
	# 		else:
	# 			k -= b_[indb-1];
	# 			ans += indb
	# 			b_ = func(b_[indb:], b_[indb-1])
	# 	else:
	# 		k -= b_[indb-1];
	# 		ans += indb
	# 		b_ = func(b_[indb:], b_[indb-1])
	ans = f(0, 0, 0)
	print(ans)





		

if __name__ == "__main__":
	solve()

Fixed submission:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = [0]+read(); arr2 = [0]+read()
	for i in range(1, n+1):arr1[i] += arr1[i-1]
	for i in range(1, m+1):arr2[i] += arr2[i-1]

	i = 0; ans = 0
	while i < n+1 and arr1[i] <= k:
		tem = i + bisect(arr2, k-arr1[i])-1
		# print(tem, i, arr1[i], bisect(arr2, k-arr1[i]))
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()

Buggy python submission (verdict: Runtime Error):
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)

# def func(arr, b):
# 	return([i-b for i in arr])

# def f(i, j, t):
# 	if t >=k:
# 		return(i+j)
# 	return(max(f(i+1, j, t+a_[i+1]), f(i, j+1, t+b_[j+1])))



def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	dic = {}
	def f(i, j, t):
		# print(i, j, t, "******")
		key = (i, j, t)
		if key in dic:
			return(dic[key])
		if t == k:
			# print(i, j, t, "11111")
			return(i+j)
		if t > k:
			# print(i, j, t, "22222")
			return(i+j-1)
		if i ==a and j ==b:
			# print(i, j, t, "0"*5)
			return(i+j)
		if i == a:
			return(f(i, j+1, t + b_[j]))
		if j == b:
			return(f(i+1, j, t + a_[i]))
		

		x = f(i+1, j, t+a_[i]) if i < a else 0#f(i+1, j, t)
		y = f(i, j+1, t+b_[j]) if j < b else 0#f(i, j+1, t)
		dic[key] = max(x, y)
		return(dic[key])
	# for i in range(1, a): a_[i] += a_[i-1]
	# for i in range(1, b): b_[i] += b_[i-1]
	# ans = 0
	# while k > 0:
	# 	inda = bisect(a_, k); indb = bisect(b_, k)
	# 	# print(k, inda, indb, a_[inda-1], b_[indb-1])
	# 	if inda > indb:
	# 		k -= a_[inda-1];
	# 		ans += inda
	# 		a_ = func(a_[inda:], a_[inda-1])
	# 	elif inda == indb:
	# 		if a_[inda-1] < b_[indb-1]:
	# 			k -= a_[inda-1];
	# 			ans += inda
	# 			a_ = func(a_[inda:], a_[inda-1])
	# 		else:
	# 			k -= b_[indb-1];
	# 			ans += indb
	# 			b_ = func(b_[indb:], b_[indb-1])
	# 	else:
	# 		k -= b_[indb-1];
	# 		ans += indb
	# 		b_ = func(b_[indb:], b_[indb-1])
	ans = f(0, 0, 0)
	print(ans)





		

if __name__ == "__main__":
	solve()

Fixed submission:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = [0]+read(); arr2 = [0]+read()
	for i in range(1, n+1):arr1[i] += arr1[i-1]
	for i in range(1, m+1):arr2[i] += arr2[i-1]

	i = 0; ans = 0
	while i < n+1 and arr1[i] <= k:
		tem = i + bisect(arr2, k-arr1[i])-1
		# print(tem, i, arr1[i], bisect(arr2, k-arr1[i]))
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()

Buggy python submission (verdict: Runtime Error):
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)

def func(arr, b):
	return([i-b for i in arr])

def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	for i in range(1, a): a_[i] += a_[i-1]
	for i in range(1, b): b_[i] += b_[i-1]
	ans = 0
	while k > 0:
		inda = bisect(a_, k); indb = bisect(b_, k)
		# print(k, inda, indb, a_[inda-1], b_[indb-1])
		if inda > indb:
			k -= a_[inda-1];
			ans += inda
			a_ = func(a_[inda:], a_[inda-1])
		elif inda == indb:
			if a_[inda-1] < b_[indb-1]:
				k -= a_[inda-1];
				ans += inda
				a_ = func(a_[inda:], a_[inda-1])
			else:
				k -= b_[indb-1];
				ans += indb
				b_ = func(b_[indb:], b_[indb-1])
		else:
			k -= b_[indb-1];
			ans += indb
			b_ = func(b_[indb:], b_[indb-1])


	print(ans)





		

if __name__ == "__main__":
	solve()

Fixed submission:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = [0]+read(); arr2 = [0]+read()
	for i in range(1, n+1):arr1[i] += arr1[i-1]
	for i in range(1, m+1):arr2[i] += arr2[i-1]

	i = 0; ans = 0
	while i < n+1 and arr1[i] <= k:
		tem = i + bisect(arr2, k-arr1[i])-1
		# print(tem, i, arr1[i], bisect(arr2, k-arr1[i]))
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()

Buggy python submission (verdict: Runtime Error):
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	a, b, k = read(); a_ = read(); b_ = read()
	for i in range(1, a): a_[i] += a_[i-1]
	for i in range(1, b): b_[i] += b_[i-1]
	ans = 0
	while k > 0:
		inda = bisect(a_, k); indb = bisect(b_, k)
		# print(k, inda, indb, a_[inda-1], b_[indb-1])
		if inda > indb:
			k -= a_[inda-1];
			ans += inda
			a_ = a_[inda:]
		elif inda == indb:
			if a_[inda-1] < b_[indb-1]:
				k -= a_[inda-1];
				ans += inda
				a_ = a_[inda:]
			else:
				k -= b_[indb-1];
				ans += indb
				b_ = b_[indb:]
		else:
			k -= b_[indb-1];
			ans += indb
			b_ = b_[indb:]


	print(ans)





		

if __name__ == "__main__":
	solve()

Fixed submission:
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = [0]+read(); arr2 = [0]+read()
	for i in range(1, n+1):arr1[i] += arr1[i-1]
	for i in range(1, m+1):arr2[i] += arr2[i-1]

	i = 0; ans = 0
	while i < n+1 and arr1[i] <= k:
		tem = i + bisect(arr2, k-arr1[i])-1
		# print(tem, i, arr1[i], bisect(arr2, k-arr1[i]))
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()