Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque


def _tsundoku(n, m, k, a, b):
    # print(f'{a=}')
    # print(f'{b=}')
    a_len = len(a)
    b_len = len(b)

    ans = [0, 0, 0]

    L = []
    d = deque()
    d.append((0, 0, 0))
    while d:
        # print(d, L)
        a_readed, b_readed, t = d.popleft()
        if not (a_len > a_readed and t + a[a_readed] <= k) and not (b_len > b_readed and t + b[b_readed] <= k):
            # print(a_readed, b_readed, t)
            L.append(a_readed + b_readed)
        else:
            if a_len > a_readed and t + a[a_readed] <= k:
                d.append((a_readed + 1, b_readed, t + a[a_readed]))
            if b_len > b_readed and t + b[b_readed] <= k:
                d.append((a_readed, b_readed + 1, t + b[b_readed]))
    ans = max(L)
    return ans

def tsundoku(f):
    readline = f.readline
    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)

def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import sys
from itertools import accumulate


def _tsundoku(n, m, k, a, b):
    a_temp = tuple(accumulate(a, initial=0))
    b_temp = tuple(accumulate(b, initial=0))

    ans = 0
    b_index = m
    for a_index in range(n + 1):
        if a_temp[a_index] > k:
            break
        while a_temp[a_index] + b_temp[b_index] > k:
            b_index -= 1
        else:
            ans = max(ans, a_index + b_index)
    return ans


def tsundoku(f):
    readline = f.readline
    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)


def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import functools
from collections import deque

readline = sys.stdin.buffer.readline
n, m, k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))

a_len = len(a)
b_len = len(b)


ans = [0, 0, 0]

L = []
d = deque()
d.append((0, 0, 0))
while d:
    a_readed, b_readed, t = d.popleft()
    if not (a_len > a_readed and t + a[a_readed] < k) and not (b_len > b_readed and t + b[b_readed] < k):
        L.append(a_readed + b_readed)
    else:
        if a_len > a_readed and t + a[a_readed] < k:
            d.append((a_readed + 1, b_readed, t + a[a_readed]))
        if b_len > b_readed and t + b[b_readed] < k:
            d.append((a_readed, b_readed + 1, t + b[a_readed]))

ans = max(L)
print(ans)


Fixed submission:
import sys
from itertools import accumulate


def _tsundoku(n, m, k, a, b):
    a_temp = tuple(accumulate(a, initial=0))
    b_temp = tuple(accumulate(b, initial=0))

    ans = 0
    b_index = m
    for a_index in range(n + 1):
        if a_temp[a_index] > k:
            break
        while a_temp[a_index] + b_temp[b_index] > k:
            b_index -= 1
        else:
            ans = max(ans, a_index + b_index)
    return ans


def tsundoku(f):
    readline = f.readline
    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)


def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import functools
from collections import deque

readline = sys.stdin.buffer.readline
n, m, k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))

a_len = len(a)
b_len = len(b)


ans = [0, 0, 0]

L = []
d = deque()
d.append((0, 0, 0))
while d:
    a_readed, b_readed, t = d.popleft()
    if not (a_len > a_readed and t + a[a_readed] <= k) and not (b_len > b_readed and t + b[b_readed] <= k):
        L.append(a_readed + b_readed)
    else:
        if a_len > a_readed and t + a[a_readed] <= k:
            d.append((a_readed + 1, b_readed, t + a[a_readed]))
        if b_len > b_readed and t + b[b_readed] <= k:
            d.append((a_readed, b_readed + 1, t + b[a_readed]))

ans = max(L)
print(ans)

Fixed submission:
import sys
from itertools import accumulate


def _tsundoku(n, m, k, a, b):
    a_temp = tuple(accumulate(a, initial=0))
    b_temp = tuple(accumulate(b, initial=0))

    ans = 0
    b_index = m
    for a_index in range(n + 1):
        if a_temp[a_index] > k:
            break
        while a_temp[a_index] + b_temp[b_index] > k:
            b_index -= 1
        else:
            ans = max(ans, a_index + b_index)
    return ans


def tsundoku(f):
    readline = f.readline
    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)


def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import functools
from collections import deque

readline = sys.stdin.buffer.readline
n, m, k = map(int, readline().split())
a = list(map(int, readline().split()))
b = list(map(int, readline().split()))

a_len = len(a)
b_len = len(b)


ans = [0, 0, 0]

L = []
d = deque()
d.append((0, 0, 0))
while d:
    a_readed, b_readed, t = d.popleft()
    if (a_len <= a_readed or t + a[a_readed] >= k) and (b_len <= b_readed or t + b[b_readed] >= k):
        L.append(a_readed + b_readed)
    else:
        if a_len > a_readed and t + a[a_readed] <= k:
            d.append((a_readed + 1, b_readed, t + a[a_readed]))
        if b_len > b_readed and t + b[b_readed] <= k:
            d.append((a_readed, b_readed + 1, t + b[a_readed]))

ans = max(L)
print(ans)

Fixed submission:
import sys
from itertools import accumulate


def _tsundoku(n, m, k, a, b):
    a_temp = tuple(accumulate(a, initial=0))
    b_temp = tuple(accumulate(b, initial=0))

    ans = 0
    b_index = m
    for a_index in range(n + 1):
        if a_temp[a_index] > k:
            break
        while a_temp[a_index] + b_temp[b_index] > k:
            b_index -= 1
        else:
            ans = max(ans, a_index + b_index)
    return ans


def tsundoku(f):
    readline = f.readline
    n, m, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)


def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()