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

    time = 0
    i = 0
    while (time + A[i] <= K):
        time += A[i]
        i += 1
        if i == N:
            break

    i2 = i-1#i2はAの一番下の変数を指すポインタ
    h = 0
    while (time + B[h] <= K):
        time += B[h]
        h += 1
        i += 1
        if h == M:
            break
    max = i
    #iは冊数

    i3 = i#今後比べていくときの合計冊数
    #print(time,i)
    if h == M:
        return max

    for j in range(i2+1):
        if i2 < 0:
            return max
        time -= A[i2]
        i3 -= 1
        while (time + B[h] <= K):
            time += B[h]
            h += 1
            i3 += 1
            if h == M:
                break
        #print(time,i3)

        if i3 > max:
            max = i3

        i2 -= 1

    return max

print(main())


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

    time = 0
    i = 0
    while (time + A[i] <= K):
        time += A[i]
        i += 1
        if i == N:
            break

    i2 = i-1#i2はAの一番下の変数を指すポインタ
    h = 0
    while (time + B[h] <= K):
        time += B[h]
        h += 1
        i += 1
        if h == M:
            break
    max = i
    #iは冊数

    i3 = i#今後比べていくときの合計冊数
    #print(time,i)
    if h == M:
        return max

    for j in range(i2+1):
        if i2 < 0:
            return max
        time -= A[i2]
        i3 -= 1
        while (time + B[h] <= K):
            time += B[h]
            h += 1
            i3 += 1
            if h == M:
                break
        #print(time,i3)

        if i3 > max:
            max = i3

        i2 -= 1
        if h == M:
            return max

    return max

print(main())

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

    time = 0
    i = 0
    while (time + A[i] <= K):
        time += A[i]
        i += 1
        if i == N:
            break

    i2 = i-1#i2はAの一番下の変数を指すポインタ
    h = 0
    while (time + B[h] <= K):
        time += B[h]
        h += 1
        i += 1
        if h == M:
            break
    max = i
    #iは冊数

    i3 = i#今後比べていくときの合計冊数
    #print(time,i)
    if h == M:
        return max

    for j in range(i2+1):
        time -= A[i2]
        i3 -= 1
        while (time + B[h] <= K):
            time += B[h]
            h += 1
            i3 += 1
            if h == M:
                break
        #print(time,i3)

        if i3 > max:
            max = i3

        i2 -= 1

    return max

print(main())


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

    time = 0
    i = 0
    while (time + A[i] <= K):
        time += A[i]
        i += 1
        if i == N:
            break

    i2 = i-1#i2はAの一番下の変数を指すポインタ
    h = 0
    while (time + B[h] <= K):
        time += B[h]
        h += 1
        i += 1
        if h == M:
            break
    max = i
    #iは冊数

    i3 = i#今後比べていくときの合計冊数
    #print(time,i)
    if h == M:
        return max

    for j in range(i2+1):
        if i2 < 0:
            return max
        time -= A[i2]
        i3 -= 1
        while (time + B[h] <= K):
            time += B[h]
            h += 1
            i3 += 1
            if h == M:
                break
        #print(time,i3)

        if i3 > max:
            max = i3

        i2 -= 1
        if h == M:
            return max

    return max

print(main())