Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    A = [0 for i in range(len(a))]
    B = [0 for i in range(len(b))]
    A[0] = a[0]
    B[0] = b[0]

    for i in range(1, len(a)):
        A[i] = A[i-1]+a[i]
    for i in range(1, len(b)):
        B[i] = B[i-1]+b[i]

    index = m-1
    ans = [0]
    for i in range(len(a)):
        rest = k - A[i]
        if rest < 0:
            break

        while B[index] > rest:
            index -= 1
            if index == 0:
                break
        ans.append(i + index+2)

    print(max(ans))

    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()


Fixed submission:
#!/usr/bin/env python3
import sys
from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    A, B = [0], [0]

    for i in range(len(a)):
        A.append(A[i]+a[i])
    for i in range(len(b)):
        B.append(B[i]+b[i])

    index = m
    ans = [0]
    for i in range(len(a)+1):
        rest = k - A[i]
        if rest < 0:
            break

        while B[index] > rest:
            index -= 1

        ans.append(i + index)

    print(max(ans))


    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    read = []
    isAll = False

    while sum(read) <= k:
        if len(a) == 0 and len(b) == 0:
            isAll = True
            break
        if len(a) == 0 or a[0] >= b[0]:
            b_top = b.popleft()
            read.append(b_top)
            continue
        if len(b) == 0 or a[0] < b[0]:
            a_top = a.popleft()
            read.append(a_top)
            continue

    if isAll:
        print(len(read))
    else:
        print(len(read) - 1)


# oj t -c "pypy3 main.py"
# acc s main.py -- --guess-python-interpreter pypy
main()


Fixed submission:
#!/usr/bin/env python3
import sys
from collections import deque


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


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


def main():
    n, m, k = MI()
    a = deque(LI())
    b = deque(LI())

    A, B = [0], [0]

    for i in range(len(a)):
        A.append(A[i]+a[i])
    for i in range(len(b)):
        B.append(B[i]+b[i])

    index = m
    ans = [0]
    for i in range(len(a)+1):
        rest = k - A[i]
        if rest < 0:
            break

        while B[index] > rest:
            index -= 1

        ans.append(i + index)

    print(max(ans))


    # oj t -c "pypy3 main.py"
    # acc s main.py -- --guess-python-interpreter pypy
main()