Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    _n, _m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    sum = 0
    count = 0
    for v in ns:
        if sum + v > k:
            break
        else:
            sum += v
            count += 1

    ans_now = count
    ans = ans_now
    i = count - 1
    for v in ms:
        if sum + v > k:
            while sum + v > k:
                sum -= ns[i]
                i -= 1
                ans_now -= 1
                if i < 0:
                    break
            if sum + v > k:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    _n, _m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    sum = 0
    count = 0
    for v in ns:
        if sum + v > k:
            break
        else:
            sum += v
            count += 1

    ans_now = count
    ans = ans_now
    i = count - 1
    for v in ms:
        if sum + v > k:
            while sum + v > k:
                if i < 0:
                    break
                sum -= ns[i]
                i -= 1
                ans_now -= 1
            if sum + v > k:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n, m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    # 全部Aの場合上からなんこ取れるかを見つつ、Bを入れて押し出していく
    sum = 0
    last_flg = False
    for (i, v) in enumerate(ns):
        if sum + v > k:
            break
        else:
            sum += v
        if i == len(ns) - 1:
            last_flg = True

    if last_flg:
        i += 1
    ans_now = i
    ans = ans_now
    i -= 1
    for v in ms:
        break_flg = False
        if sum + v > k:
            while sum + v > k:
                sum -= ns[i]
                i -= 1
                ans_now -= 1
                if i == 0:
                    break_flg = True
                    break
            if break_flg:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    _n, _m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    sum = 0
    count = 0
    for v in ns:
        if sum + v > k:
            break
        else:
            sum += v
            count += 1

    ans_now = count
    ans = ans_now
    i = count - 1
    for v in ms:
        if sum + v > k:
            while sum + v > k:
                if i < 0:
                    break
                sum -= ns[i]
                i -= 1
                ans_now -= 1
            if sum + v > k:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()