Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
ans = 0
for i in range(n+1)[::-1]:
    for j in range(m+1)[::-1]:
        if c[i] + d[j] <= k:
            ans = max(ans,i+j)
            break
print(ans)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
ans = 0
for i in range(n+1)[::-1]:
    for j in range(m+1)[::-1]:
        if c[i] + d[j] <= k:
            ans = max(ans,i+j)
            break
print(ans)


Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
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()))

x = 0
for i in range(n):
    x += a[i]
    a[i] = x

x = 0
for i in range(m):
    x += b[i]
    b[i] = x

x = 0
for i in range(n):
    x = a[i]
    if x > k:
        x = a[i-1]
        ans = i
        j = i-2
        break
    if i + 1 == n:
        ans = n
        j = i-1

y = 0
for i in range(m):
    y = b[i]
    if x + y > k:
        while x + y > k and j >= 0:
            x = b[j]
            j -= 1
    if x + y <= k:
        ans = max(ans,i+j+2)

print(ans)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
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()))

x = 0
for i in range(n):
    x += a[i]
    a[i] = x

x = 0
for i in range(m):
    x += b[i]
    b[i] = x

x = 0
for i in range(n):
    x = a[i]
    if x > k:
        x = a[i-1]
        ans = i
        j = i-1
        break
    if i + 1 == n:
        ans = n
        j = i

y = 0
for i in range(m):
    y = b[i]
    if x + y > k:
        while x + y > k and j != -1:
            x = b[j]
            j -= 1
    if x + y <= k:
        ans = max(ans,i+j+2)

print(ans)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)

Buggy python submission (verdict: Runtime Error):
#n = a の本:m = b の本
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
p = 0
z = 0
i = 0
j = 0

while p < k:
    if a[i] <= b[j]:
        p += a[i]
        z += 1
        i += 1
    else:
        p += b[j]
        z += 1
        j += 1
    if p > k:
        z -= 1

print(z)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)

Buggy python submission (verdict: Runtime Error):
#n = a の本:m = b の本
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
p = 0
z = 0
i = 0
j = 0

while p < k:
    if a[i] < b[j]:
        p += a[i]
        z += 1
        i += 1
    elif a[i] > b[j]:
        p += b[j]
        z += 1
        j += 1
    else:
        if a[i+1] < b[j+1]:
            p += a[i]
            z += 1
            i += 1
        elif:
            p += b[j]
            z += 1
            j += 1

print(z)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)

Buggy python submission (verdict: Runtime Error):
#n = a の本:m = b の本
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
p = 0
i = 0
j = 0
while p < k:
    if a[i] < b[j]:
        p += 1
        i += 1
    elif a[i] > b[j]:
        p += 1
        j += 1
    else:
        if a[i+1] < b[j+1]:
            p += 1
            i += 1
        else:
            p += 1
            j += 1

print(p)

Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = [0]*(n+1)
d = [0]*(m+1)
for i in range(n):
    c[i+1] = a[i]+c[i]
for i in range(m):
    d[i+1] = b[i]+d[i]
for i in range(m+1)[::-1]:
    if d[i] <= k:
        x = i
        break
ans = x
for i in range(1,n+1):
    while c[i] + d[x] > k:
        if x >= 1:
            x -= 1
        else:
            break
    if c[i] + d[x] <= k:
        ans = max(ans,i+x)
print(ans)