Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for i in range(iter_max):
        if cum1[i] > limit:
            break
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(i + 1 + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = list(accumulate(A_list))
cum_b = list(accumulate(B_list))

if cum_a[0] < cum_b[0]:
    print(search(cum_a, cum_b, N))
else:
    print(search(cum_b, cum_a, M))


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for (i,) in range(iter_max):
        if cum1[i] > limit:
            cur = 0
        else:
            cur = i
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(cur + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = [0] + list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
for i, a in enumerate(cum_a):
    if a > K:
        cur = 0
    else:
        cur = i
    cand = bisect_right(cum_b, K - a)
    ans = max(cur + cand, ans)

print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max):
    ans = 0
    for i in range(iter_max):
        if cum1[i] > K:
            break
        cand = bisect_right(cum2, K - cum1[i])
        ans = max(i + 1 + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
if cum_a[0] < cum_b[0]:
    print(search(cum_a, cum_b, N))
else:
    print(search(cum_b, cum_a, N))


Fixed submission:
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for (i,) in range(iter_max):
        if cum1[i] > limit:
            cur = 0
        else:
            cur = i
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(cur + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = [0] + list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
for i, a in enumerate(cum_a):
    if a > K:
        cur = 0
    else:
        cur = i
    cand = bisect_right(cum_b, K - a)
    ans = max(cur + cand, ans)

print(ans)