peterverebics/CodeNet_Python_118 huggingface dataset:
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 = [0] + list(map(int, input().split()))
B = [0] + 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]

b = M
r = 0
for i,a in enumerate(A):
	if a > K:
		break
	while a+B[b]>K and b>=0:
		b -= 1
	r = max(r, i+b)

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

ma = [0] * (N + 1)
mb = [0]*(M+1)


for i in range(N):
    ma[i + 1] = ma[i] + A[i]

for i in range(M):
    mb[i + 1] = mb[i] + B[i]

j = M
max_num = 0

for i in range(N+1):
    if ma[i] > K:
        break
    while ma[i] + mb[j] > K:
        j -= 1
    max_num = max(max_num, i + j)
print(max_num)
#!/usr/bin/env python3
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 = 0
j = m
for i in range(n + 1):
    if A[i] > k:
        break
    while j > 0 and k - A[i] < B[j]:
        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])

res = 0
j = 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)
nums=[int(e) for e in input().split()]
A=[int(e) for e in input().split()]
B=[int(e) for e in input().split()]

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

ans, j = 0, nums[1]
for i in range(nums[0]+1):
    if a[i] > nums[2]:
        break
    while b[j] > nums[2] - 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(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(0, 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]+a[i]>k:
    j -= 1
  ans = max(ans,i+j)

print(ans)
N, M, K = map(int, input().split())
A = [0] + [int(i) for i in input().split()]
B = [0] + [int(i) for i in input().split()]

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

ret = 0
a = N - 1
b = 0
while b < M :
  while a >= 0 and A[a] + B[b] > K :
    a -= 1
  if a >= 0 and A[a] + B[b] <= K :
    ret = max(ret, a + b)
  b += 1
  
print(ret)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_a = sum(A)
sum_b = 0
b_next_ind = 0
ans = 0

# 下からi冊減らす; i=0..N
for i in range(N + 1):
	sum_b_max = K - sum_a
	if sum_b_max >= 0:
		while b_next_ind < M and sum_b + B[b_next_ind] <= sum_b_max:
			sum_b += B[b_next_ind]
			b_next_ind += 1
		ans = max(ans, (N - i) + b_next_ind)
	sum_a -= A[N - 1 - i]

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])
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)
import sys
input = lambda: sys.stdin.readline().rstrip()
import bisect

def cumsum(a):
   r = [0]
   for v in a:
      r.append(r[-1] + v)
   return r

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

ans = 0
for a_num, v in enumerate(a):
   tmp = 0
   if k >= v:
      b_num = bisect.bisect_right(b, k - v) - 1
      tmp = a_num + b_num
   ans = max(ans, tmp)
print(ans)
import bisect
import itertools
n,m,k=map(int,input().split())
A=list(itertools.accumulate([0]+list(map(int,input().split()))))
B=list(itertools.accumulate([0]+list(map(int,input().split()))))

ans=0
for i,a in enumerate(A):
    if a>k:
        break
    cnt=bisect.bisect_right(B,k-a)-1
    ans=max(ans,i+cnt)
print(ans)
import sys
readline = sys.stdin.readline

N,M,K = map(int,readline().split())
A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().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]

ans = 0
b_ind = len(B) - 1
for i in range(len(A)):
  if A[i] > K:
    break
  while b_ind >= 0 and A[i] + B[b_ind] > K:
    b_ind -= 1
    
  if ans < i + b_ind:
    ans = i + b_ind
    
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
t = sum(B)
j = M
for i in range(N+1):
    while j > 0 and t > K:
        j -= 1
        t -= B[j]
    if t > K:
        break
    ans = max(ans, i+j)
    if i == N:
        break
    t += A[i]
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)
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    a = [0]+list(itertools.accumulate(a))
    b = [0]+list(itertools.accumulate(b))
    res = 0
    j = m
    best=0
    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)


if __name__ == '__main__':
    main()
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
asum=0
bsum=0
pointer=0
while pointer<m and bsum+b[pointer]<=k:
	bsum+=b[pointer]
	pointer+=1
ans=pointer
for i in range(n):
	asum+=a[i]
	while asum+bsum>k and pointer>=0:
		pointer-=1
		bsum-=b[pointer]
	if asum+bsum>k:
		break
	ans=max(ans,(i+1)+pointer)
print(ans)
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
tot_a=0
tot_b=0
#Aだけでどこまでいけるか
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])
#print(a,b)
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)
from itertools import accumulate

N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
cumsum_A, cumsum_B = [0] + list(accumulate(A)), [0] + list(accumulate(B))
ans = 0
j = M
for i in range(N+1):
    if cumsum_A[i] > K: break
    while cumsum_A[i] + cumsum_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, 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())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n):
  acum1.append(acum1[-1]+arr1[i])
acum2=[0]
for i in range(m):
  acum2.append(acum2[-1]+arr2[i])
ans=0
j=m
for i in range(n+1):
  if acum1[i]>k:
    break
  while acum2[j]>k-acum1[i] and j>0:
    j-=1
  ans=max(ans,i+j)
print(ans)
import bisect

def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c,d=Csum(a),Csum(b)
d.pop(0)
ans=0
for i in range(n+1):
    if k-c[i]<0:
        break
    ans=max(ans,i+bisect.bisect_right(d,k-c[i]))
print(ans)
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
import itertools
A = list(itertools.accumulate(A))
B = list(itertools.accumulate(B))
ans=0
b=M
for a in range(N+1):
  if A[a]>K:
    break
  while  A[a]+B[b]>K:
    b-=1
  ans=max(ans,a+b)
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()))
for i in range(n-1): a[i+1] = a[i] + a[i+1]
for i in range(m-1): b[i+1] = b[i] + b[i+1]
a = [0] + a; b = [0] + b

c = bisect_right(a, k)-1
ans = 0

for i in range(c+1)[::-1]:
    r = k-a[i]
    j = bisect_right(b, r)-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()))

c = [0]
d = [0]
for i in range(n):
    c.append(c[i] + a[i])
for i in range(m):
    d.append(d[i] + b[i])

ans = 0
j = m
for i in range(n + 1):
    if c[i] > k:
        break
    while c[i] + d[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,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
import numpy as np
from numba import jit, njit
input = lambda: sys.stdin.buffer.readline().rstrip()

@njit
def main(n,m,k,sa,sb):
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  return(rx)

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = np.cumsum([0]+a)
sb = np.cumsum([0]+b)
print(main(n,m,k,sa,sb))
import bisect
from itertools import accumulate

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

A_cumsum = list(accumulate(A))
B_cumsum = list(accumulate(B))

max_books = 0
for a, A_sum in enumerate([0] + A_cumsum):
    if A_sum > K:
        break
    else:
        b = bisect.bisect(B_cumsum, K - A_sum)
        max_books = max(a + b, max_books)

print(max_books)
from sys import stdin

n, m, k = map(int, stdin.readline().rstrip().split())

a = list(map(int, stdin.readline().rstrip().split()))
b = list(map(int, stdin.readline().rstrip().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 A[i]  > k- B[j]:
        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_right
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
accu = 0
aa = [0]
for i in a:
    accu += i
    aa.append(accu)
accu = 0
bb = [0]
for i in b:
    accu += i
    bb.append(accu)
ans = 0
for i in range(n+1):
    if aa[i]>k:
        break
    tmp = i+bisect_right(bb, k-aa[i])-1
    ans = max(tmp, ans)
print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = [0]
y = [0]
for i in range(n):
    x.append(x[i] + a[i])
    
for i in range(m):
    y.append(y[i] + b[i])
    
i = 0
j = m
ans = 0
while i <= n and 0 <= j:
    if x[i] + y[j] <= k:
        ans = max(ans, i + j)
        i += 1
    else:
        j -= 1

print(ans)
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_time = [0]
b_time = [0]

for i in range(n):
    a_time.append(a_time[-1] + a[i])
for j in range(m):
    b_time.append(b_time[-1] + b[j])

j = m
cnt = 0

for i in range(n+1):
    if a_time[i] > k:
        continue

    while j > 0 and a_time[i] + b_time[j] > k:
        j -= 1
    cnt = max(cnt, i + j)

print(cnt)
n, m, k = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
b_list = list(map(int, input().split(' ')))
sa = [0] * (n+1)
sb = [0] * (m+1)

for i in range(n):
  sa[i+1] = a_list[i] + sa[i]
for j in range(m):
  sb[j+1] = b_list[j] + sb[j]

best=0
r = m
for i, a in enumerate(sa):
  if a>k:
    break
  while ((a + sb[r]) > k) & (r>=0):
    r-=1
    
  best = max(best,i+r)
      
  
    
print(best)
from bisect import bisect_right as br
from itertools import accumulate as ac
n,m,k=map(int,input().split())
a=list(ac([0]+list(map(int,input().split()))))
b=list(ac([0]+list(map(int,input().split()))))
l=0
for i in range(n+1):
    if k<a[i]:
        break
    else:
        l=max(l,i+br(b,k-a[i])-1)
print(l)
import bisect
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
ans = 0
for i in range(1, n):
    a[i+1] += a[i]
for i in range(1, m):
    b[i+1] += b[i]
for i in range(n+1):
    res = k - a[i]
    if res<0: continue
    index = bisect.bisect_right(b, res)
    ans = max(ans, index+i-1)
print(ans)
#import sys
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
l = M
for k in range(N+1):
    if a[k] > K:
        break
    while b[l] > K - a[k]:
        l -= 1
    ans = max(ans,k+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])

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
input = sys.stdin.readline

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

    import itertools
    ac = [0] + list(itertools.accumulate(A))
    bc = [0] + list(itertools.accumulate(B))
    ans, j = 0, M
    for i, a in enumerate(ac):
        if a > K:
            break
        while a + bc[j] > K:
            j -= 1
        ans = max(ans, i+j)
    print(ans)

if __name__ == '__main__':
    main()
N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]


ans, j = 0, M
for i in range(N + 1):
    if arui[i] > K:
        break
    while brui[j] > K - arui[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = list(map(int, input().split()))
  b = list(map(int, input().split()))
  sa = np.cumsum([0]+a)
  sb = np.cumsum([0]+b)
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()
import sys
input = sys.stdin.buffer.readline

import bisect
N, M, K = map(int, input().split())
A = list(map(int, (input().split())))
B = list(map(int, (input().split())))
cumA, cumB = [0], [0]
for a in A:
    cumA.append(cumA[-1]+a)
for b in B:
    cumB.append(cumB[-1]+b)
ans = 0
for i in range(N, -1, -1):
    if cumA[i] > K: continue
    j = bisect.bisect_right(cumB, K-cumA[i])
    ans = max(ans, i+j-1)
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]
T = 0
ans = 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 a[i] + b[j] > K:
    j -= 1
  ans = max(ans, i + j)


print(ans)
from bisect import bisect_right
from itertools import accumulate

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

a_ac=[0]+list(accumulate(a))
b_ac=[0]+list(accumulate(b))

ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    continue
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_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])
  
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
from numpy import cumsum

n, m, k = map(int, input().split())
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))
a_cum = cumsum(alst)
b_cum = cumsum(blst)
ans = bisect_right(b_cum, k)
for i, num in enumerate(a_cum, start = 1):
    if num > k:
        break
    tmp = k - num
    ans = max(ans, bisect_right(b_cum, tmp) + i)
print(ans)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0

A = [0]*(n+1)

for i in range(n):
    A[i+1] = A[i] + a[i]

B = [0]*(m+1)

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

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 = [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)
from itertools import accumulate
from bisect import bisect_right
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A = list(filter(lambda x: x <= k, accumulate(A)))
B = list(filter(lambda x: x <= k, accumulate(B)))
ans = 0
for i, a in enumerate(A):
    j = bisect_right(B, k-a)
    ans = max(ans, i+j+1)
ans = max(ans, len(B))
print(ans)
import numpy as np
import sys
input = sys.stdin.buffer.readline

N, M, K = map(int, input().split())
cumA = np.zeros(N+1, dtype=np.int64)
cumA[1:] = np.array(input().split(), dtype=np.int64).cumsum()
cumB = np.zeros(M+1, dtype=np.int64)
cumB[1:] = np.array(input().split(), dtype=np.int64).cumsum()
# print(cumA)
# print(cumB)

ans = 0
for i in range(N, -1, -1):
    if cumA[i] > K: continue
    j = np.searchsorted(cumB, K-cumA[i], side='right')
    ans = max(ans, i+j-1)
print(ans)
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
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(0,n+1):
	curr=a[i]
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)
from itertools import accumulate
N, M, K = map(int, input().split())
As = [0] + list(map(int, input().split()))
Bs = [0] + list(map(int, input().split()))
csum_A = list(accumulate(As))
csum_B = list(accumulate(Bs))

ok = 0
ng = N + M + 2
while ng - ok > 1:
    mid = (ng + ok) // 2
    min_time = 10 ** 9 + 10
    for t in range(max(0, mid-M), min(mid+1, N+1)):
        min_time = min(min_time, csum_A[t] + csum_B[mid - t])
    
    if K >= min_time:
        ok = mid
    else:
        ng = mid

print(ok)
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________

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

v = 0
for i in range(N):
    if v + A[i] <= K:
        v += A[i]
    else:
        mi = i-1
        break
else:
    mi = N-1

ans = mi+1

for j in range(M):
    while mi > -1 and v + B[j] > K:
        v -= A[mi]
        mi -= 1
    v += B[j]
    if v <= K:
        ans = max(ans, mi+1+ j+1)

print(ans)
N, M, K = map(int, input().split())

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

AD = [0]
for i in range(N):
    AD.append(AD[i]+A[i])
BD = [0]
for i in range(M):
    BD.append(BD[i]+B[i])

ans = 0
for i in range(N+1):
    if K < AD[i]:
        break
    else:
        while BD[M] > K - AD[i]:
            M -= 1
        ans = max(ans, i + M)

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_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(1, N+1):
    A[i] += A[i-1]

for i in range(1, M+1):
    B[i] += B[i-1]

b_cnt = M

ans = 0
for a_cnt in range(N+1):
    if A[a_cnt] > K:
        continue

    rest = K - A[a_cnt]

    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

print(ans)
#ABC172 C Tsundoku 22:34
from itertools import accumulate

n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
s_A = [0]+list(accumulate(A))
s_B = [0]+list(accumulate(B))

ans,j = 0, m
for i in range(n+1):
    if s_A[i] > k: break
    while s_B[j] > k - s_A[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=map(int,input().strip("\n").split())
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  for i in range(n+1):
    while j>0 and t>k:
      j-=1
      t-=B[j]
    if t>k:
      break
    ans=max(ans,i+j)
    if i==n:
      break
    t+=A[i]
  print(ans)