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

def chk(i,time,a,b):
    if len(a)==0 and len(b)==0:
        return i
    if time>k:
        return i-1
    
    if len(a)==0:
        tmp_a = 10**9
    else:
        tmp_a = a.popleft()
        
    if len(b)==0:
        tmp_b = 10**9
    else:
        tmp_b = b.popleft()
        
    if tmp_a>tmp_b:
        time += tmp_b
        a.appendleft(tmp_a)
        i += 1
    else:
        time += tmp_a
        b.appendleft(tmp_b)
        i += 1
        
    tmp = chk(i,time,a,b)
    return tmp

n,m,k = map(int,input().split())
tmp_a = list(map(int,input().split()))
tmp_b = list(map(int,input().split()))
a = deque()
b = deque()
a.extend(tmp_a)
b.extend(tmp_b)
#print(a,b)

print(chk(0,0,a,b))

Fixed submission:
n,m,k = map(int,input().split())
tmp_a = list(map(int,input().split()))
tmp_b = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(n):
    a.append(a[i]+tmp_a[i])
for i in range(m):
    b.append(b[i]+tmp_b[i])
#print(a)
#print(b)
ans = 0
j = m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
def dfs(kazu,i,j,ans):
    global result
    if ans>k:
        result.append(kazu-1)
        return
    elif i==n and j==m:
        result.append(kazu)
        return
    elif i==n:
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])
    elif j==m:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
    else:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

result = []

dfs(0,0,0,0)

print(max(result))

Fixed submission:
n,m,k = map(int,input().split())
tmp_a = list(map(int,input().split()))
tmp_b = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(n):
    a.append(a[i]+tmp_a[i])
for i in range(m):
    b.append(b[i]+tmp_b[i])
#print(a)
#print(b)
ans = 0
j = m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)

Buggy python submission (verdict: Runtime Error):
def dfs(kazu,i,j,ans):
    global result
    if ans>k:
        result.append(kazu-1)
        return
    elif i>=n and j>=m:
        result.append(kazu)
        return
    elif i>=n:
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])
    elif j>=m:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
    else:
        #aの本を読む
        dfs(kazu+1,i+1,j,ans+a[i])
        #bの本を読む
        dfs(kazu+1,i,j+1,ans+b[j])

n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

result = []

dfs(0,0,0,0)

print(max(result))

Fixed submission:
n,m,k = map(int,input().split())
tmp_a = list(map(int,input().split()))
tmp_b = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(n):
    a.append(a[i]+tmp_a[i])
for i in range(m):
    b.append(b[i]+tmp_b[i])
#print(a)
#print(b)
ans = 0
j = m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)