peterverebics/CodeNet_Python_118 huggingface dataset:
import bisect
n , m , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ax = [0]*(n+1)
bx = [0]*(m+1)
for i in range(1,n+1):
    ax[i]=ax[i-1]+a[i-1]
for i in range(1,m+1):
    bx[i]=bx[i-1]+b[i-1]

c = bisect.bisect_right(ax,k)
ma = 0
for i in range(c):
    d = bisect.bisect_right(bx,k-ax[i])
    ma = max(ma,i+d-1)
print(ma)
import bisect
import itertools
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

acc1 = [0]+list(itertools.accumulate(a))
acc2 = list(itertools.accumulate(b))

ans = 0
for i in range(n+1):
    num = i
    temp = acc1[i]
    rest = k-temp

    if rest >= 0:
        hoge = bisect.bisect_right(acc2,rest)

        num += hoge

        if num > ans:
            ans = num

print(ans)
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0 for i in range(n+1)]
b = [0 for j in range(m+1)]
for i in range(n):
    a[i+1] = a[i]+A[i]
for j in range(m):
    b[j+1] = b[j]+B[j]

j = m
res = 0
for i in range(n+1):
    if a[i] > k:
        break
    while k - a[i] < b[j]:
        j -= 1
    res = max(res, i+j)

print(res)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    #print(b[j],K - a[i])
    j -= 1
  ans = max(ans, i + j)
  #print("ans",ans)
print(ans)
n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=[0]+list(map(int,input().split()))

for i in range(1,n+1): a[i]=a[i]+a[i-1]
for i in range(1,m+1): b[i]=b[i]+b[i-1]
j=m
ans=0
for i in range(n+1):
    if j<0: break
    while a[i]+b[j]>k and j>=0: j-=1
    ans=max(i+j,ans)
print(ans)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
res = 0
output = 0
j = M
num = 0
for i in range(N + 1):
  if K < a[i]:
    break
  else:
    res = K - a[i]
  while b[j] > res:
    j -= 1
  num = i + j 
  output = max(output, num)
print(output)
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = map(int, open(0).read().split())
    cum_A, cum_B = tuple(accumulate([0] + AB[:N])), tuple(accumulate(AB[N:]))
    candidates = []
    for i, a_time in enumerate(cum_A):
        if a_time > K:
            candidates.append(0)
            break
        b_time = K - a_time
        candidates.append(i + bisect(cum_B, b_time))
    print(max(candidates))


if __name__ == "__main__":
    main()
n, m, k = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a, b = [0], [0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

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)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

t = sum(A)
i = N
ans = 0

for j in range(M + 1):
  while i > 0 and t > K:
    i -= 1
    t -= A[i]
  if t > K:
    break
  ans = max(ans, i + j)
  if j == M:
    break
  t += B[j]
print(ans)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

most = 0
cur = 0
tot = 0
for i in range(n):
	if tot + a[i] <= k:
		cur += 1
		tot += a[i]
		if cur > most:
			most = cur
	else:
		i -= 1
		break
j = 0
while j < m:
	if tot + b[j] <= k:
		cur += 1
		tot += b[j]
		if cur > most:
			most = cur
		j += 1
	else:
		if i >= 0:
			cur -= 1
			tot -= a[i]
			i -= 1
		else:
			break
print(most)
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]
b = [0]
for i in range(n):
    a.append(a[-1]+A[i])
for j in range(m):
    b.append(b[-1]+B[j])
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)
from bisect import bisect_right

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

sum_a = [0]
for v in a:
    sum_a.append(sum_a[-1] + v)

sum_b = [0]
for v in b:
    sum_b.append(sum_b[-1] + v)

x = bisect_right(sum_a, k)

res = 0
for i in range(x):
    res = max(res, bisect_right(sum_b, k - sum_a[i]) + i - 1)
print(res)
import bisect
n, m, k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
bc = [0]*(m+1)
for i in range(m):
    bc[i+1] = bc[i] + b[i]
bc = bc[1:]

ans = bisect.bisect_right(bc, k) # 0冊
totala = 0
na = 0
for i in range(n):
    totala += a[i]
    na += 1
    if totala == k:
        ans = max(ans, na)
        break
    elif totala > k:
        break
    ba = bisect.bisect_right(bc, k-totala)
    ans = max(ans, na+ba)
print(ans)
from bisect import bisect_left,bisect_right
n,m,k=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
for i in range(1,n):
    arr1[i]=arr1[i]+arr1[i-1]
for i in range(1,m):
    arr2[i]=arr2[i]+arr2[i-1]
ma=0
for i in range(n):
    if arr1[i]<=k:
        ma=max(ma,bisect_right(arr2,k-arr1[i])+i+1)
for i in range(m):
    if arr2[i]<=k:
        ma=max(ma,bisect_right(arr1,k-arr2[i])+i+1)
print(ma)
import bisect
N, M, K = map(int,input().split())
ls_a = list(map(int,input().split()))
ls_b = list(map(int,input().split()))

A = [0] * (N+1)
B = [0] * (M+1)
for i in range(N):
  A[i+1] = A[i] + ls_a[i]
for i in range(M):
  B[i+1] = B[i] + ls_b[i]
  
ans = 0
for i in range(N+1):
  if A[i] <= K:
    x = bisect.bisect(B,K-A[i])
    ans = max(ans, i+x-1)
print(ans)
n, m, k = map(int, input().split())
a_list = list(map(int, input().strip().split()))
b_list = list(map(int, input().strip().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i] + a_list[i])
for j in range(m):
    b.append(b[j] + b_list[j])

ans, j = 0, 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)
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0]
b = [0]
for i in range(0, n):
    a.append(A[i] + a[i])
for i in range(0, m):
    b.append(B[i] + b[i])

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)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

A, B = [0], [0]
for i in range(n):
    A.append(a[i]+A[i])
for i in range(m):
    B.append(b[i]+B[i])

ans, j = 0, 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)
from bisect import bisect_left, bisect_right

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

res = 0

cA = [0]
for i in range(N):
    cA.append(cA[-1] + A[i])

cB = [0]
for i in range(M):
    cB.append(cB[-1] + B[i])

for i in range(N + 1):
    rem = K - cA[i]
    if rem < 0:
        continue
    j = bisect_right(cB, rem)
    res = max(res, i + j - 1)

print(res)
from bisect import *
n, m, k = map(int, input().split())
A = [0]
for x in map(int, input().split()):
    x += A[-1]
    if x > k: break
    A.append(x)
B = [0]
for x in map(int, input().split()):
    x += B[-1]
    if x > k: break
    B.append(x)
ans = 0
for i in range(len(A)):
    ans = max(ans, i + (bisect_right(B, k-A[i]) - 1))
print(ans)
from itertools import accumulate, permutations

import bisect


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

A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))

ans = 0
for i in range(N+1):
    a = A[i]
    if a > K:
        continue
    r = K - a
    j = bisect.bisect(B, r) - 1
    ans = max(ans, i + j)

print(ans)
n,m,k=map(int, input().split())
*a,=map(int, input().split())
*b,=map(int, input().split())
a=[0]+a
b=[0]+b
import numpy as np
a=np.cumsum(a)
b=np.cumsum(b)
bi=m
ans=0
for i in range(n+1):
    asm=a[i]
    while a[i]+b[bi]>k and bi:
        bi-=1
    if a[i]+b[bi]<=k:
        ans=max(ans,i+bi)
print(ans)
from itertools import accumulate
from bisect import bisect_left,bisect
n, m , k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ruia = [0]
ruia.extend(list(accumulate(a)))
ruib = list(accumulate(b))
ans = 0
for i in range(n+1):
    nokori = k - ruia[i]
    if nokori < 0:
        break
    yomeru = bisect(ruib,nokori)
    ans = max(ans,i+yomeru)
print(ans)
import sys
input = sys.stdin.readline

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
res = 0
a, b = [0], [0]

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

j = m

for i in range(n+1):
    if a[i] > k:
        break
    while True:
        if a[i] + b[j] <= k:
            break
        j -= 1
    res = max(res, i+j)

print(res)
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
a,b = [0],[0]
for i in range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])
 
ans,j = 0,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)
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[-1] + a[i])

for i in range(m):
    sum_b.append(sum_b[-1] + b[i])

ans = 0
j = m
for i in range(n + 1):
    while sum_a[i] + sum_b[j] > k and j >= 0:
        j -= 1

    if j < 0:
        break

    if sum_a[i] + sum_b[j] <= k:
        ans = max(ans, i + j)

print(ans)
from bisect import bisect_right
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

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


def f(time, r):
    ret = bisect_right(r, time) - 1
    return ret


def fa(time):
    return f(time, a)


def fb(time):
    return f(time, b)

ans = 0

for i, ai in enumerate(a):
    k -= ai
    if k < 0:
        break
    ans = max(ans, i + fb(k))

print(ans)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ea=[0]
for i in range(n):
    ea.append(ea[i]+a[i])
eb=[0]
for i in range(m):
    eb.append(eb[i]+b[i])
if n>m:
    ea,eb=eb,ea
    n,m=m,n
tb=m
p=0
for i in range(n+1):
    while ea[i]+eb[tb]>k:
        if tb==0:
            break
        tb-=1
    if ea[i]+eb[tb]<=k:
        p=max(i+tb,p)
print(p)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])

ans, j = 0, M
for i in range(N+1):
    if a[i] > K: break
    while a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i+j)
    
print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [0] * (n+1)
B = [0] * (m+1)
for i in range(n):
    A[i+1] = A[i] + a[i]
for i in range(m):
    B[i+1] = B[i] + b[i]

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)
import bisect
N,M,K = map(int, input().split())
A= list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1,len(A)):
    A[i]+=A[i-1]
for i in range(1,len(B)):
    B[i]+=B[i-1]

honn=bisect.bisect(B,K)
#print(honn)
for i in range(len(A)):
    s=K-A[i]
    if s>=0:
        
        a=bisect.bisect(B,s)
        #print(s)
        if i+1+a>honn:
            honn=i+1+a
print(honn)
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


a = [0]
b = [0]

for i in range(n):
    a.append(a[i]+ A[i])
for i in range(m):
    b.append(b[i] + B[i])
# print(a)
# print(b)
# print(a[3])
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)
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int,input().split())
A = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))
B = [0]+list(accumulate(map(int,input().split()), lambda x,y:x+y))
ans = 0
for i in range(N+1):
    left = K-A[i]
    if left < 0:
        break
    j = bisect_right(B, left)
    ans = max(ans, i+j-1)
print(ans)
n,m,k=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))

a=[0]
b=[0]

for i in range(n):a.append(a[i]+aa[i])
for i in range(m):b.append(b[i]+bb[i])

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)
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
cnta = [0 for i in range(n + 1)]
cntb = [0 for i in range(m + 1)]

for i in range(n):
    cnta[i + 1] = cnta[i] + a[i]
for i in range(m):
    cntb[i + 1] = cntb[i] + b[i]
for i in range(n + 1):
    cnt = 0
    if k - cnta[i] >= 0:
        cnt = i
        cnt += min(m, bisect.bisect_right(cntb, k - cnta[i]) - 1)
    ans = max(ans, cnt)
print(ans)
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M, K = rl()
A = rl()
B = rl()

s = 0
for i, b in enumerate(B):
	s += b
	B[i] = s

import bisect

ans = 0
s = 0
j = bisect.bisect_right(B, K)
ans = j
for i, a in enumerate(A):
	s += a
	if s > K:
		break
	j = bisect.bisect_right(B, K-s)
	#print(i, j)
	n = i+1 + j
	ans = max(ans, n)
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

nmax = 0

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break

    while b[j] + a[i] > K:
        j -= 1
    ans = max(ans, i+j)

print(ans)
exit()
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
a=[0];b=[0];ans=0;j=m
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
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)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

aa=[a[0]]
for i in range(n-1):
    aa.append(aa[i]+a[i+1])
aa.insert(0,0)
bb=[b[0]]
for i in range(m-1):
    bb.append(bb[i]+b[i+1])
    
import bisect
l=[]
for i in range(n+1):
    p=k-aa[i]
    if p>=0:
        l.append(i+bisect.bisect_right(bb,p))
    else:
        break
print(max(l))
import bisect
N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

bsum = [0]
for b in B:
    bsum.append(bsum[-1]+b)

ans = bisect.bisect_right(bsum,K) -1
asum = 0
for n,a in enumerate(A):
    asum += a
    if asum > K:
        break
    m = bisect.bisect_right(bsum,K-asum)
    if ans < m+n:
        ans = m+ n
print(ans)
from bisect import bisect_right as br
n,m,k = map(int,input().split())
a = [int(i) for i in input().split()]
sa = [0]*(n+1)
for i in range(n): sa[i+1] = sa[i]+a[i]
b = [int(i) for i in input().split()]
sb = [0]*(m+1)
for i in range(m): sb[i+1] = sb[i]+b[i]
ans = 0
for i in range(n+1):
    cnt = sa[i]
    if cnt > k: break
    ans = max(ans,br(sb,k-cnt)-1+i)
print(ans)
from itertools import accumulate
from bisect import bisect_right

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

acc_a = list(accumulate(a))
acc_b = list(accumulate(b))

ans = 0
for i, e in enumerate(acc_b):
    if e > k:
        break
    a_cnt = bisect_right(acc_a, k - e)
    ans = max(ans, i + a_cnt)

print(ans)
n, m, k = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
ls = an[::-1] + bn
l = 0
r = n
s = sum(an)
ans = 0
while r < n + m and l <= n:
    if s <= k:
        ans = max(ans, r - l)
        s += ls[r]
        r += 1
    else:
        s -= ls[l]
        l += 1
if s <= k:
    ans = max(ans, r-l)
print(ans)
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A,B = [0],[0]

for i in range(n):
  A.append(a[i] + A[i])
for i in range(m):
  B.append(b[i] + B[i])

num,x = 0,m

for i in range(n+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)
N, M, K = map(int, input().split(' '))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] += B_ls[i]
b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt >= 0:
        b_cnt -=1
    rst = max(rst, a_cnt + b_cnt)
print(rst)
import numpy as np

n, m, k = map(int, input().split())
a = np.array([0] + input().split(), dtype=int)
b = np.array([0] + input().split(), dtype=int)

cum_a = a.cumsum()
cum_b = b.cumsum()

maximum = 0
j = 0
for i in range(n, -1, -1):
  rest = k - cum_a[i]
  if rest < 0:
    continue
  while rest - cum_b[j] >= 0:
    j += 1
    if j > m:
      break
  j -= 1
  maximum = max(maximum, i + j)
print(maximum)
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M, K = map(int, readline().split())
AB = np.array(read().split(), np.int64)
A = AB[:N]
B = AB[N:]

Acum = np.zeros(N + 1, np.int64)
Acum[1:] = np.cumsum(A)
Bcum = np.zeros(M + 1, np.int64)
Bcum[1:] = np.cumsum(B)

Acum = Acum[Acum <= K]
Bcum = Bcum[Bcum <= K]

x = np.searchsorted(Acum, K - Bcum, side='right') - 1
x += np.arange(len(Bcum))

print(x.max())
import numpy as np
import bisect
from decimal import Decimal
n, m, k = map(int, input().split())
aa = list(map(Decimal, input().split()))
bb = list(map(Decimal, input().split()))
aasum = np.cumsum(aa)
bbsum = np.cumsum(bb)
an = bisect.bisect_right(aasum, k)
bn = bisect.bisect_right(bbsum, k)
ret = max(an, bn)
for i in range(n):
    if k - aasum[i] < 0:
        break
    v = bisect.bisect_right(bbsum, k - aasum[i])
    if v+i+1>ret:
        ret = v+i+1
print(ret)
N,M,K = map(int,input().split())

A = list(map(int, input().split()))
B =list(map(int, input().split()))

sumA=[0]
sumB=[0]


for i in range(N):
  sumA.append(sumA[-1]+A[i])
for i in range(M):
  sumB.append(sumB[-1]+B[i])

  
total=0
startB=len(sumB)-1
for a in range(len(sumA)):
  for b in range(startB,-1,-1):
    if sumA[a]+sumB[b]<=K:
      total=max(total,a+b)
      startB=b
      break
  if sumA[a]>K:
    break
    
print(total)
from itertools import accumulate
from bisect import bisect_right
N, M, K = [int(x) for x in input().split()]
A = [0] + [int(x) for x in input().split()]
B = [0] + [int(x) for x in input().split()]

cumA = list(accumulate(A))
cumB = list(accumulate(B))

ans = 0
for i in range(N + 1):
    if cumA[i] > K: break
    Tb = K - cumA[i]
    temp = i + bisect_right(cumB, Tb) - 1
    ans = max(ans, temp)

print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = 0
sum_a = [0]
for i in range(n):
  if t + a[i] <= k:
    t += a[i]
    sum_a.append(t)
  else:
    break
sum_b = [0]
t = 0
for i in range(m):
  if t + b[i] <= k:
    t += b[i]
    sum_b.append(t)
  else:
    break
ans = []
j = 0
for i in range(len(sum_a)):
  while sum_a[i] + sum_b[len(sum_b) - j - 1] > k:
    j += 1
  ans.append(i + len(sum_b) - j - 1)
print(max(ans))
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A = [0] + A
B = [0] + B
for i in range(N):
    A[i + 1] += A[i]
for i in range(M):
    B[i + 1] += B[i]

res, j = 0, M
for i in range(N + 1):
    if A[i] > K:
        break
    while B[j] > K - A[i]:
        j -= 1
    res = max(res, i + j)
print(res)
N,M,K=map(int, input().split())
A = [0]
B = [0]
A += list(map(int, input().split()))
B += list(map(int, input().split()))
for i in range(N):
  A[i+1] += A[i]
for i in range(M):
  B[i+1] += B[i]
j = 0
ans = 0
for i in range(N,-1,-1):
  while (j <= M) and (A[i] + B[j] <= K):
    ans = max(ans, i+j)
#    print(i,j,A[i],B[j], A[i] + B[j], ans)
    j += 1
print(ans)
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())

dp = [0]*(N+1)
tot, lb = sum(B), M
while tot > K: 
    tot -= B.pop(-1)
    lb -= 1
dp[0] = lb

for i in range(N):
    K -= A[i]
    if K < 0:
        continue
    while tot > K and lb > 0: 
        tot -= B.pop(-1)
        lb -= 1
    dp[i+1] = i+1 + lb

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

A = [0]
B = [0]

for i in range(n):
    A.append(A[i]+a[i])

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

A,B = [0],[0]

for i in range(n):
    A.append(A[i] + a[i])
for i in range(m):
    B.append(B[i] + b[i])

ans,j = 0,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)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
a, b = [0], [0]
 
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])
 
ans, j = 0, 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)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, 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)
n,m,k = map(int,input().split())

A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

a, b = [0], [0]
for i in range(n):
     a.append(a[i] + A[i])
for i in range(m):
     b.append(b[i] + B[i])

ans, j = 0, 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)
import sys
from itertools import accumulate

n,m,k=map(int, input().split())
a = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
b = [0] + list(accumulate(map(int,sys.stdin.readline().rstrip().split())))
ans = 0
j = m

#print(a,b)

for i,item in enumerate(a):
        if k<item:
            break
        while k<item+b[j]:
            j -= 1
        ans = max(ans,i+j)

print(ans)
import bisect

n,m,k = map(int,input().split())
a = [0]+list(map(int,input().split()))
b = [0]+list(map(int,input().split()))

for i in range(1,n+1):
  a[i] = a[i]+a[i-1]
for j in range(1,m+1):
  b[j] = b[j]+b[j-1]

book_cnt=0
for a_cnt in range(n+1):
  if a[a_cnt]>k:
    continue
  rest=k-a[a_cnt]
  b_cnt=bisect.bisect(b,rest)-1
  book_cnt=max(book_cnt,a_cnt+b_cnt)

print(book_cnt)
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]

for i in range(N):
    a.append(a[i] + A[i])
for j in range(M):
    b.append(b[j] + B[j])
ans = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1
    ans = max(ans, i+j)
print(ans)