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
time = 0
a_time = 0
temp = 0
if a[0] > k:
    j = 0
    while time <= k:
        time += b[j]
        j += 1
        ans += 1
else:
    for i in range(n):
        a_time += a[i]
        if a_time > k:
            break
        else:
            time = a_time
            j = 0
            while time <= k:
                time += b[j]
                j += 1
            temp = i + 1 + j            
            if temp > ans:
                ans = temp
                
print(ans)

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for j in range(m):
    sum_b.append(sum_b[j] + b[j])

temp = 0
j = m
ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        temp = i -1
        if temp > ans:
            ans = temp
        break
    else:
        while k - sum_a[i] < sum_b[j]:
            j -= 1
        temp = i + j
        if temp > ans:
            ans = temp
            
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
time = 0
a_time = 0
temp = 0
if a[0] > k:
    j = 0
    while time <= k:
        time += b[j]
        j += 1
        ans += 1
else:
    for i in range(n):
        a_time += a[i]
        if a_time > k:
            break
        else:
            time = a_time
            temp = i + 1
            j = 0
            while time <= k:
                time += b[j]
                j += 1
                temp +=1
            temp += j
            if temp > ans:
                ans = temp
                
print(ans)

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for j in range(m):
    sum_b.append(sum_b[j] + b[j])

temp = 0
j = m
ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        temp = i -1
        if temp > ans:
            ans = temp
        break
    else:
        while k - sum_a[i] < sum_b[j]:
            j -= 1
        temp = i + j
        if temp > ans:
            ans = temp
            
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
time = 0
 
 
for i in range(len(a)):
    time += a[i]
    if time > k:
        time -=a[i]
        break
    ans += 1
    
count_a = ans
 
for j in range(len(b)):
    time += b[j]
    if time > k:
        while count_a > 0 & time > k:
            time -= a[count_a]
            count_a -= 1
        if time > k:
            tmp = 0
        else:
            tmp = count_a + j
    if tmp > ans :
        ans = tmp
    
print(ans)

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

sum_a = [0]
sum_b = [0]

for i in range(n):
    sum_a.append(sum_a[i] + a[i])
for j in range(m):
    sum_b.append(sum_b[j] + b[j])

temp = 0
j = m
ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        temp = i -1
        if temp > ans:
            ans = temp
        break
    else:
        while k - sum_a[i] < sum_b[j]:
            j -= 1
        temp = i + j
        if temp > ans:
            ans = temp
            
print(ans)