Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def upper_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok




def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] += a[i-1]
	for i in range(1, m):
		b[i] += a[i-1]
	log.print(a, b)
	ans = upper_case(b, k)
	for i in range(n):
		if a[i] > k:
			continue
		ans = max(ans, i+1+upper_case(b, k-a[i]))
		log.print(i, k-a[i], upper_case(b, k-a[i]))
	print(ans)


main()

Fixed submission:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def upper_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok




def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] += a[i-1]
	for i in range(1, m):
		b[i] += b[i-1]
	log.print(a, b)
	ans = upper_case(b, k)
	log.print(ans, b, k)
	for i in range(-1, n):
		if a[i] > k:
			continue
		ans = max(ans, i+1+upper_case(b, k-a[i]))
		log.print(i, k-a[i], upper_case(b, k-a[i]))
	print(ans)


main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def upper_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok




def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] += a[i-1]
	for i in range(1, m):
		b[i] += a[i-1]
	log.print(a, b)
	ans = 0
	for i in range(-1, n):
		if i == -1:
			ans = max(ans, upper_case(b, k))
			continue
		if a[i] > k:
			continue
		ans = max(ans, i+1+upper_case(b, k-a[i]))
		log.print(i, k-a[i], upper_case(b, k-a[i]))
	print(ans)


main()

Fixed submission:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def upper_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok




def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] += a[i-1]
	for i in range(1, m):
		b[i] += b[i-1]
	log.print(a, b)
	ans = upper_case(b, k)
	log.print(ans, b, k)
	for i in range(-1, n):
		if a[i] > k:
			continue
		ans = max(ans, i+1+upper_case(b, k-a[i]))
		log.print(i, k-a[i], upper_case(b, k-a[i]))
	print(ans)


main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def lower_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok



def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] += a[i-1]
	for i in range(1, m):
		b[i] += a[i-1]
	log.print(a, b)
	ans = 0
	for i in range(-1, n):
		if a[i] > k or i == -1:
			ans = max(ans, lower_case(b, k))
			continue
		ans = max(ans, i+1+lower_case(b, k-a[i]))
		log.print(i, k-a[i], lower_case(b, k-a[i]))
	print(ans)


main()

Fixed submission:
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def upper_case(lst, key):
	ng = -1
	ok = len(lst)
	while (abs(ok - ng) > 1):
		mid = (ok + ng) // 2
		if lst[mid] > key:
			ok = mid
		else:
			ng = mid
	return ok




def main():
	log = Logger(0)
	n, m, k = map(int, sys.stdin.readline().split())
	a = list(map(int, sys.stdin.readline().split()))
	b = list(map(int, sys.stdin.readline().split()))
	for i in range(1, n):
		a[i] += a[i-1]
	for i in range(1, m):
		b[i] += b[i-1]
	log.print(a, b)
	ans = upper_case(b, k)
	log.print(ans, b, k)
	for i in range(-1, n):
		if a[i] > k:
			continue
		ans = max(ans, i+1+upper_case(b, k-a[i]))
		log.print(i, k-a[i], upper_case(b, k-a[i]))
	print(ans)


main()