Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
t = 0
a = 0
b = 0

while True:
    if not t + A[a] > K:
        t += A[a]
        a += 1
        # print(a, t, A[a-1])
        if a >= N:
            break
    else:
        break

flug = True     #全探索を行うか
while True:
    if not t + B[b] > K:
        t += B[b]
        b += 1
        # print(b, t, B[b-1])
        if b >= M:
            flug = False
            break
    else:
        break

# print(a, b, flug)
ans = a + b
flug2 = True    #処理を続けるか
if flug:
    while True:
        a -= 1
        t -= A[a]
        while True:
            if not t + B[b] > K:
                t += B[b]
                b += 1
                if b >= M:
                    flug2 = False
                    break
            else:
                break
        ans = max(ans, a + b)
        if not flug2:
            break
print(ans)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
t = 0
a = 0
b = 0

while True:
    if not t + A[a] > K:
        t += A[a]
        a += 1
        # print(a, t, A[a-1])
        if a >= N:
            break
    else:
        break

flug = True     #全探索を行うか
while True:
    if not t + B[b] > K:
        t += B[b]
        b += 1
        # print(b, t, B[b-1])
        if b >= M:
            flug = False
            break
    else:
        break

# print(a, b, flug)
ans = a + b
flug2 = True    #処理を続けるか
if flug:
    while True:
        a -= 1
        if a < 0:
            break
        t -= A[a]
        while True:
            if not t + B[b] > K:
                t += B[b]
                b += 1
                if b >= M:
                    flug2 = False
                    break
            else:
                break
        ans = max(ans, a + b)
        if not flug2:
            break
print(ans)

Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
t = 0
a = 0
b = 0

while True:
    if not t + A[a] > K:
        t += A[a]
        a += 1
        # print(a, t, A[a-1])
        if a >= N:
            break
    else:
        break

flug = True     #全探索を行うか
while True:
    if not t + B[b] > K:
        t += B[b]
        b += 1
        # print(b, t, B[b-1])
        if b >= M:
            flug = False
            break
    else:
        break

# print(a, b, flug)
ans = a + b
flug2 = True    #処理を続けるか
if flug:
    while True:
        a -= 1
        t -= A[a]
        while True:
            if not t + B[b] > K:
                t += B[a]
                b += 1
                if b >= M:
                    flug2 = False
                    break
            else:
                break
        ans = max(ans, a + b)
        if not flug2:
            break
print(ans)

Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
t = 0
a = 0
b = 0

while True:
    if not t + A[a] > K:
        t += A[a]
        a += 1
        # print(a, t, A[a-1])
        if a >= N:
            break
    else:
        break

flug = True     #全探索を行うか
while True:
    if not t + B[b] > K:
        t += B[b]
        b += 1
        # print(b, t, B[b-1])
        if b >= M:
            flug = False
            break
    else:
        break

# print(a, b, flug)
ans = a + b
flug2 = True    #処理を続けるか
if flug:
    while True:
        a -= 1
        if a < 0:
            break
        t -= A[a]
        while True:
            if not t + B[b] > K:
                t += B[b]
                b += 1
                if b >= M:
                    flug2 = False
                    break
            else:
                break
        ans = max(ans, a + b)
        if not flug2:
            break
print(ans)