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()))

from bisect import bisect_right
if n>m:
    a, b = b, a
    n, m = m, n
c = [b[0]]
for i in range(1, m):
    c.append(c[-1]+b[i])
a.insert(0,0)
x = 0
result = [0]
for i in range(n+1):
    x += a[i]
    if x > k:
        break
    y = k - x
    z = bisect_right(c, y)
    result.append(z+i)
print(max(result))
m, n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
asum = [0]
bsum = [0]
for i in range(m):
  asum.append(asum[i]+a[i])
for i in range(n):
  bsum.append(bsum[i]+b[i])
j = n
max = 0
for i in range(m+1):
    if asum[i] > k:
        break
    while asum[i] + bsum[j] > k:
        j-=1
    if i+j > max:
        max = i+j
print(max)
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]
ans = 0
for i in range(1,len(A)+1):
    sum_a.append(sum_a[i - 1] + A[i - 1])
for i in range(1,len(B)+1):
    sum_b.append(sum_b[i - 1] + B[i - 1])


j = len(sum_b)-1
for i in range(len(sum_a)):
    if sum_a[i] > K: break
    while (sum_b[j] + sum_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)
from itertools import *
from bisect import bisect_right
n,m,time = 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(bisect_right(A, time)-1,-1,-1):
    ans = max(ans,i+bisect_right(B, time-A[i])-1)
print(ans)
from bisect import bisect_right
from itertools import accumulate
N, M, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

accA = list(accumulate(As)) + [0]
accB = list(accumulate(Bs))

ans = 0
for numA in range(N+1):
    t = accA[numA-1]
    if t > K:
        break
    numB = bisect_right(accB, K-t)
    tmp = numA + numB
    ans = ans if ans > tmp else tmp
print(ans)
import bisect
n,m,k = map(int,input().split())
*a, = map(int,input().split())
*b, = map(int,input().split())

sa = [0] * (n+1)
sa[0] = 0
for i in range(1,n+1):
    sa[i] = sa[i-1] + a[i-1]
sb = [0] * m
sb[0] = b[0]
for i in range(1,m):
    sb[i] = sb[i-1] + b[i]

ans = 0
for i in range(n+1):
    rest = k - sa[i]
    if rest < 0:break
    a_s = i
    b_s = bisect.bisect(sb,rest) 
    ans = max(ans, a_s + b_s)
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 = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
A_sum = sum(A)
B_sum = 0
n, m = N, 0
ans= 0
while m != M:
  if A_sum + B_sum <= K:
    ans = max(ans, n+m)
    m += 1
    B_sum += B[m]
  elif A_sum + B_sum > K and n >= 0:
    A_sum -= A[n]
    n -= 1
  else:
    break
if A_sum + B_sum <= K:
  ans = max(ans, n+m)    
print(ans)
from bisect import bisect_right as br
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
time=0
allB=0
AA=[0]
BB=[0]
for i in range(N):
  AA.append(A[i]+AA[-1])
for i in range(M):
  BB.append(B[i]+BB[-1])

allB=br(BB,K)-1
ans=0
for i in range(allB,-1,-1):
  #print(i)
  ans=max(ans,i+br(AA,K-BB[i])-1)
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

best = 0

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

totalA = [0]
totalB = [0]
sumA = 0
for i in range(N):
    sumA += A[i]
    totalA.append(sumA)
sumB = 0
for i in range(M):
    sumB += B[i]
    totalB.append(sumB)

iB = M
countMax = 0
for iA in range(N+1):
  if totalA[iA]>K:
    break
  else:
    while totalA[iA] + totalB[iB] > K:
      iB -= 1
  countMax = max(countMax,iA+iB)

print(countMax)
n, m, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
A = [0]
B = [0]

for i in range(len(a)):
	A.append(A[-1] + a[i])
for i in range(len(b)):
	B.append(B[-1] + b[i])

y = len(B) - 1
ans = 0
for i in range(len(A)):
	while A[i] + B[y] > x:
		y -= 1
		if y == -1:
			break
	if y == -1:
		break
	if i + y > ans:
		ans = i + y

print(ans)
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 
import bisect
N,M,K = map(int,input().split())
a_list = np.array([0]+list(map(int,input().split())))
b_list = np.array(list(map(int,input().split())))


a_list = a_list.cumsum()
b_list = b_list.cumsum()

max_cnt = 0
for i in range(N+1):
    if a_list[i]>K:
        continue
    cnt = i
    bT = K - a_list[i] + 1
    cnt += bisect.bisect_left(b_list,bT)
    if cnt >max_cnt:
        max_cnt = cnt

print(max_cnt)
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()))

from itertools import accumulate
a_acc=list(accumulate(a))
b_acc=list(accumulate(b))
a_acc.insert(0,0)
b_acc.insert(0,0)

ans=0
j=m

for i in range(n+1):
    nokori=k-a_acc[i]
    if nokori<0:
        break
    while b_acc[j]>nokori:
        j-=1
    ans=max(ans,i+j)
    # print(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, 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)
#C
import itertools
import bisect

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

cA = [0] + list(itertools.accumulate(A))
cB = list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(len(cA)):
    tmp = cA[-(i+1)]
    if tmp < k:
        indb = bisect.bisect_right(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    elif tmp == k:
        ans = n - i
    
print(ans)
import numpy as np
N, M, K = [int(x) for x in input().split(' ')]
A =  [int(x) for x in input().split(' ')]
B =  [int(x) for x in input().split(' ')]
cA = np.cumsum([0] + A)
cB = np.cumsum([0] + B)
ans = 0
for nA in range(len(cA)):
  if K < cA[nA]:
    break
  time_left = K - cA[nA]
  nB = np.searchsorted(cB, time_left, side='right') - 1
  #print(nA, cA[nA], time_left, nB, cB[nB])
  ans = max(ans, nA + nB)
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 = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

ans = 0
for i in range(N + 1):
    if a[i] > K:
        break
    j = bisect_right(b, K - a[i]) - 1
    ans = max(ans, i + j)

print(ans)
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

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


sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + a_list[i])
for i in range(M):
    b.append(b[i] + b_list[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_li = [0] + list(map(int,input().split()))
b_li = [0] + list(map(int,input().split()))

for i in range(1,n+1):
    a_li[i] += a_li[i-1]
for i in range(1,m+1):
    b_li[i] += b_li[i-1]

ans = 0
b_cnt = m
for a_cnt in range(n+1):
    if a_li[a_cnt] > k:
        continue
    while a_li[a_cnt] + b_li[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans,a_cnt+b_cnt)
print(ans)
import numpy
import bisect
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = [0]+list(numpy.cumsum(A))
b = [0]+list(numpy.cumsum(B))
ans = 0
# print(a,b)
for i in range(len(a)):
    x = k - a[i]
    if x >= 0:
        j = bisect.bisect_right(b,x)-1
        ans = max(ans, i+j)
print(ans)
import bisect
N,M,K=map(int,input().split())
SumA=[0]*(N+1)
SumB=[0]*(M+1)
A=list(map(int, input().split()))
B=list(map(int,input().split()))
for i in range(1,N+1):
    SumA[i]= A[i-1]+SumA[i-1]
for i in range(1,M+1):
    SumB[i] = B[i-1]+SumB[i-1]

ans = 0
for i in range(N+1):
    num = i
    rest = K-SumA[i]
    if rest<0:
        break;
    num += bisect.bisect_right(SumB, rest)-1
    ans = max(num, 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, 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 for _ in range(N+1)]
b = [0 for _ in range(M+1)]

for i in range(1,N+1):
  a[i] = a[i-1] + A[i-1]
  
for j in range(1,M+1):
  b[j] = b[j-1] + B[j-1]
  
num = M
ans = 0
for k in range(N+1):
  if a[k] > K:
    break
  while b[num] > K - a[k]:
    num -= 1
  ans = max(ans, k+num)
  
print(ans)
n, m, k = map(int, input().split())
a_books = list(map(int,input().split()))
b_books = list(map(int,input().split()))
sum1 = [0]
sum2 = [0]
for i in range(n):
 sum1.append(sum1[-1]+a_books[i])
for i in range(m):
 sum2.append(sum2[-1]+b_books[i])
ans=0
import bisect
for i in range(n+1):
    if sum1[i] > k:
        break
    j = bisect.bisect_right(sum2, k-sum1[i])-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 bisect


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


cnt = 0
ru_a = [0] * (n + 1)
ru_b = [0] * (m + 1)
for i in range(n):
    ru_a[i + 1] = ru_a[i] + a[i]
for i in range(m):
    ru_b[i + 1] = ru_b[i] + b[i]

ans = 0
for i in range(n + 1):
    if ru_a[i] > k:
        continue
    ind = bisect.bisect_right(ru_b, k - ru_a[i])
    ans = max(i + ind - 1, ans)
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(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_left,bisect_right
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))
import bisect
n,m,k=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
ds=[0]
for i in range(n):
    ds.append(ds[-1]+s[i])
ans=0
p=0
for i in range(m+1):
    if i>0:
        p+=t[i-1]
    if p>k:
        break
    si=bisect.bisect_left(ds,k-p+1)
    ans=max(ans,si+i-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]
for i in a:
  A.append(i+A[-1])
for i in b:
  B.append(i+B[-1])
  
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()))
book_a = [0] * (n + 1)
book_b = [0] * (m + 1)

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

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

r = m
ans = 0

for i in range(n + 1):
    if book_a[i] > k:
        break
    while book_a[i] + book_b[r] > k:
        r -= 1
    ans = max(ans, i + r)

print(ans)
import numpy as np
N, M, K = map(int, input().split())
A = np.cumsum([0] + list(map(int, input().split())))
B = np.cumsum([0] + list(map(int, input().split())))
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)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

tmp = 0
aa = [0]*(n+1)
for i in range(n):
    tmp += a[i]
    aa[i+1] = tmp

tmp = 0
bb = [0]*(m+1)
for i in range(m):
    tmp += b[i]
    bb[i+1] = tmp

j = m
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k-aa[i] and j >= 0:
        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 = 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)
import itertools
import bisect
n,m,k=map(int,input().split())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
count=0
book=0
rest=0
ans=[]
aaa=list(itertools.accumulate(aa))
bbb=list(itertools.accumulate(bb))
bs=bisect.bisect(bbb,k)
ap=bisect.bisect(aaa,k)
ans.append(ap)
for i in range(bs+1):
  ii=bs-i
  rest=k-bbb[ii-1]
  goal=bisect.bisect(aaa,rest)
  ans.append(ii+goal)
  #print(ii,goal,rest)

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

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

for i in range(n + 1):
  ren = k - a1[i]
  if ren < 0:
    break
  j = bisect.bisect_right(b1, ren)
  x = max (x, i + j)	
print (x)
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 = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = [0]
bb = [0]

for s in range(n):
    aa.append(aa[s] + a[s])
for s in range(m):
    bb.append(bb[s] + b[s])      
ans = 0
j = m

for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k - aa[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)
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
j = 0
for i, b in enumerate(B):
	if s+b > K:
		break
	s += b
	j += 1

ans = j
j -= 1
for i, a in enumerate(A):
	s += a
	while j >= 0 and s > K :
		s -= B[j]
		j -= 1
	if s > K: break
	ans = max(ans, i+1+j+1)
print(ans)
from itertools import accumulate


def solve(string):
    from bisect import bisect_right
    n, m, k, *ab = map(int, string.split())
    a, b = [0] + ab[:n], [0] + ab[n:]
    a, b = list(accumulate(a)), list(accumulate(b))
    ans = 0
    for i in range(n + 1):
        c = bisect_right(b, k - a[i]) - 1
        if c != -1:
            ans = max(ans, c + i)
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))
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)
# 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 = accumulate(AB[:N], initial=0), tuple(accumulate(AB[N:]))
    candidates = [0]
    for i, a in enumerate(cum_A):
        if a > K:
            break
        candidates.append(i + bisect(cum_B, K - a))
    print(max(candidates))


if __name__ == "__main__":
    main()
import itertools
import bisect
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a = [0] + list(itertools.accumulate(A))
b = [0] + list(itertools.accumulate(B))

result = 0
for i in range(N + 1):
    if a[i] > K:
        break
    j = bisect.bisect_right(b, K - a[i])
    result = max(result, i + j - 1)
print(result)
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
# bを全部読む
j = M

for i in range(N + 1):
    # aは0冊から始まる
    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 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]+b[j]>k:
    j-=1
  ans=max(ans,i+j)
print(ans)
N,M,K=map(int,input().strip().split())
A=list(map(int,input().strip().split()))
B=list(map(int,input().strip().split()))

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

num=0
bmax=M+1
for n in range(N+1):
    if a[n]>K:
        break
    for m in reversed(range(bmax)):
        if b[m]<=K-a[n]:
            num=max(num,n+m)
            bmax=m+1
            break
print(num)
from bisect import*
from itertools import*
n,m,k,*x=map(int,open(0).read().split());c=accumulate;b=[*c(x[n:])];print(max(i+bisect(b,k-v)for i,v in enumerate(c([0]+x[:n]))if v<=k))
N,M,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=list(map(int,input().split()))
x=sum(B)
y=M-1
r=0
for i in range(N+1):
    x+=A[i]
    while x>K and y>=0:
        x-=B[y]
        y-=1
    if x<=K:
        r=max(r,i+y+1)
print(r)
N, M, K = map(int, input().split())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
s = 0
for i, a in enumerate(A):
    if s + a > K:
        break
    s += a
else:
    i += 1
for j, b in enumerate(B):
    if s + b > K:
        break
    s += b
else:
    j += 1

ans = i + j
while i:
    i -= 1
    s -= A[i]
    while j < M and s + B[j] <= K:
        s += 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()))
ans = 0

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])

j = m

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[j] > k:
        j -= 1
    else:
        ans = max(ans, i + j)
print(ans)
from itertools import accumulate

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


As = list(accumulate(A))
Bs = list(accumulate(B))

ans = 0
idx = M-1
for i in range(N):    
    if As[i] > K:  
        break
    while idx != -1 and As[i] + Bs[idx] > K:
        idx -= 1
    num = i + idx + 2
    ans = max(ans, num)

for i in range(M):
    if Bs[i] <= K:
        ans = max(ans, i+1)
print(ans)
n,m,k=map(int,input().split())
al=[int(i) for i in input().split()]
bl=[int(i) for i in input().split()]
aa,bb=[0],[0]
for i in range(n):
    aa.append(aa[i]+al[i])
for i in range(m):
    bb.append(bb[i]+bl[i])
ans=0
j=m
for i in range(n+1):
    if aa[i]>k:
        break
    while bb[j]>k-aa[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()))
from itertools import accumulate
ar=[0]+list(accumulate(a))
bru=[0]+list(accumulate(b))
from bisect import bisect_left as bl,bisect_right as br
ans=0

for i in range(n+1):
    g=ar[i]
    if g>k:break
    if k-g>=bru[-1]:ans=max(ans,i+m);continue
    j=br(bru,k-g)
    ans=max(ans,i+j-1)
    #print(i,j-1)
print(ans)
import sys
import itertools
import bisect

N, M, K = map(int, input().split())
A = list(map(int, sys.stdin.readline().rsplit()))
B = list(map(int, sys.stdin.readline().rsplit()))

sA = [0] + list(itertools.accumulate(A))
sB = [0] + list(itertools.accumulate(B))

res = 0
for i, a in enumerate(sA):
    if K < a:
        break
    j = bisect.bisect_right(sB, K - a) - 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()))

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

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

j = M
ans = 0
for i in range(N + 1):
    if x[i] > K:
        continue
    while j >= 0 and x[i] + y[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()))

def ruiseki(lst):
    return [0]+list(accumulate(lst))

ar = ruiseki(A)
br = ruiseki(B)
ans = 0
for i in range(1+N):
    left = K - ar[i]
    if left < 0:
        continue
    bidx = bisect_right(br, left) - 1
    ans = max(ans,i+bidx)

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, 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)