peterverebics/CodeNet_Python_118 huggingface dataset:
from collections import deque
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k >= 0:
        if ad[0] > bd[0]:
            bd.popleft()
        else:
            ad.popleft()
        count += 1
    else:
        break
print(count)
from itertools import accumulate

n,m,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

la = [0] + list(accumulate(a))
lb = [0] + list(accumulate(b))

ans = 0
i = n
for j in range(m+1):
    while la[i]+lb[j] > k and i>=0:
        i -= 1
    if i==0 and lb[j] > k:
        break
    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(" ")))
total,count = 0,0
for i in range(max(n,m)):
	if i < n:
		if total+a[i] > k:
			break
		else:
			total += a[i]
			count +=1
	if i < m:
		if total+b[i] > k:
			break
		else:
			total += b[i]
			count += 1
print(count)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

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

for i in range(N):
    if A[i]>K:
        idx=i-1
        break

idx2=-1
for i in range(idx,-1,-1):
    while idx2<M-1 and A[idx]+B[idx2+1]<=K:
        idx2+=1
    ans=max(ans,idx+idx2+2)

print(ans)
from functools import reduce

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

a_sum = [0]
for i in range(len(A)):
    a_sum.append(a_sum[-1]+A[i])
    
b_sum = [0]
for i in range(len(B)):
    b_sum.append(b_sum[-1]+B[i])

max_time = 0
for i in range(len(a_sum)):
    for j in range(len(b_sum)-1, -1, -1):
        if a_sum[i]+b_sum[j] <= K:
            max_time = i+j
            break
print(max_time)
from itertools import accumulate
from bisect import bisect_right

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

ans = 0
for i, a in enumerate(A):
    if a > K:
        break
    n = bisect_right(B, K-a)
    ans = max(ans, i+n+1)

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

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

C = A + B
C.sort()

count = 0

for i in C:
  if i <= K:
    K -= i
    count += 1
    
print(count)
from collections import deque as q
import bisect

N,M,K=map(int,input().split())
As=q(map(int,input().split()))
Bs=q(map(int,input().split()))

s=[0]*(N+M)
c=0
for i in range(N+M):
    if len(As)==0:
        book=Bs.popleft()
    elif len(Bs)==0:
        book=As.popleft()
    else:
        if As[0] < Bs[0]:
            book=As.popleft()
        else:
            book=Bs.popleft()
    c+=book
    s[i]=c
i=bisect.bisect(s,K)
print(i)
n,m,k=[int(_) for _ in input().split()]
A=[int(_) for _ in input().split()]
B=[int(_) for _ in input().split()]
jikan=0
yomi=0
while (A or B):
    if A and B:
        if A[0]<B[0]:
            jikan+=A.pop(0)
        else:
            jikan+=B.pop(0)
    elif A:
        jikan+=A.pop(0)
    else:
        jikan+=B.pop(0)
    
    if jikan<=k:
        yomi+=1
print(yomi)
a, b, c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = list(map(int, input().split()))
n = 0
while True:
  try: 
    if d[0] > e[0]:
      c -= e[0]
      e.pop(0)
    else:
      c -= d[0]
      d.pop(0)
  except IndexError:
    if len(d) == 0 and len(e) == 0:
      break
    if len(d) == 0:
      c -= e[0]
      e.pop(0)
    else:
      c -= d[0]
      d.pop(0)
  n += 1
  if c < 0:
    break
print(n)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0

for x in range(n):
  sum1=0
  ans1=0
 
  sum1=sum(a[0:x])
  if sum1>k:
    break
  else:
  	ans1+=1
  for y in range(m):
    
      
    sum1+=b[y]
    if sum1>k:
      break
    else:
      ans1+=1
      if ans1>ans:
         ans=ans1
        
print(ans)
n,m,k = map(int,input().split())
A = [int(p) for p in input().split()]
B = [int(p) for p in input().split()]
count = 0

for _ in range(n+m):
  if A[0] > k and B[0] > k:
    break
  if A[0] < B[0]:
    k -= A.pop(0)
    count += 1
  else:
    k -= B.pop(0)
    count += 1
  if len(A)==0:
    A.append((10**9)+1)
  if len(B)==0:
    B.append((10**9)+1)
print(count)
import random
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=random.randint(0,n+m)
print(ans)
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(300000)
b.append(300000)
c = []
e = 0
f = 0
for i in range(len(a)):
    b.append(a[i])
while sum(c) < k:
    if a[e] <= b[f]:
        c.append(a[e])
        e += 1
    else:
        c.append(b[f])
        f += 1
        
if 300000 in c:
    c.remove(300000)
if sum(c) == k:
    print(len(c))
else:
    print(len(c)-1)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
from bisect import bisect_right
dpa = [0]
for a in A:
    dpa.append(dpa[-1]+a)
dpb = [0]
for b in B:
    dpb.append(dpb[-1]+b)
ans = 0
for i in range(1, N+1):
    t = dpa[i]
    if t > K:
        break
    j = bisect_right(dpb, K-t)
    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.append(10**9)
b.append(10**9)
# k分以内
ans=0
i=0
while True:
    ans+=min(a[0],b[0])
    if a[0]>b[0]:
        b.pop(0)
    else:
        a.pop(0)
        
    if ans>k:
        print(i)
        quit()
    i+=1
[N, M, K] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

c = 0

A.append(10**10)
A.reverse()
B.append(10**10)
B.reverse()
a = A.pop()
b = B.pop()

while True:
  if a < b:
    if K >= a:
      c += 1
      K -= a
      a = A.pop()
    else:
      break
  else:
    if K >= b:
      c += 1
      K -= b
      b = B.pop()
    else:
      break

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

from itertools import accumulate
import bisect
z = list(accumulate(sorted(a+b)))

print(bisect.bisect_right(z, k))
n,m,k = map(int, input().split())
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))

def csum(l,ll):
    s = 0
    res = [0] * ll
    for i in range(ll):
        s += l[i]
        res[i] = s
    return res

csln = csum(ln,n)
cslm = csum(lm,m)

import numpy as np

lk = [k-x for x in csln if k-x >=0]
res = np.searchsorted(np.array(cslm), np.array(lk), side='right')
rmax = 0
for i,j in zip(range(1,len(lk)+1), res):
    rmax = max(rmax, i+j)
print(rmax)
n,m,k=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ni = 0
mi = 0
ans = 0

for i in range(n+m):
  if n == ni and m == mi:
    break
  elif n == ni:
    ans += b[mi]
    mi += 1
  elif m == mi:
    ans += a[ni]
    ni += 1
  elif a[ni] <= b[mi]:
    ans += a[ni]
    ni += 1
  else:
    ans += b[mi]
    mi += 1

  if ans > k:
    break

cal = ni + mi
if k < ans :
  cal -= 1
print(cal)
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans1 = 0
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]
import bisect
key = bisect.bisect(a,k)
for i in range(key+1):
    ans = 0
    ans += key-i
    time = a[key-i-1]
    ans += bisect.bisect(b,k-time)
    ans1 = max(ans1,ans)

            
print(ans1)
import bisect
from itertools import accumulate

n, m, k = map(int, input().split())
a = tuple(accumulate(map(int, input().split())))
b = tuple(accumulate(map(int, input().split())))
s = 0

cnt = 0
for i, j in enumerate(a):
    s += j
    if j <= k:
        cnt = max(cnt, i + bisect.bisect_right(b, k - s) + 2)
print(cnt)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
A.append(10**9+1)
A.append(10**9+1)
B.append(10**9+1)
B.append(10**9+1)
count=0
time=0
a_current=0
b_current=0
while time<=K:
    if A[a_current]<=B[b_current]:
        time+=A[a_current]
        a_current=a_current+1
    else:
      time+=B[b_current]
      b_current+=1
    count+=1
print(count-1)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)

for i in range(n,-1,-1):
  ans=-1
  if ruia[i]>k:
    continue
  for j in range(mx,m):
    if ruia[i]+ruib[j]>k:
      ans=i+j-1
      break
  else:
    ans=i+m
  if ans>mx:
    mx=ans
print(mx)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sum = 0
c = 0
for i in range(n+m):
  if len(a) and len(b) and a[0] < b[0]:
    sum += a.pop(0)
  elif len(b):
    sum += b.pop(0)
  else:
    sum += a.pop(0)
  if sum <= k:
    c += 1
print(c)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A.append(10**9)
B.append(10**9)
cnt=0
for i in range(N+M):
    if A[0]>B[0]:
        K-=B[0]
        B.pop(0)
    else:
        K-=A[0]
        A.pop(0)
    if K>=0:
        cnt+=1
    else:
        break
print(cnt)
n,m,k=map(int,input().split())

L1=list(map(int,input().split()))
L2=list(map(int,input().split()))

L=L1+L2
L.sort()
result=0
time=0

for i in range(n+m):
    if result<=k:
        result+=L[i]
        time=i+1
        if result>k:
            time=i
            break

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

A = A + [10 ** 10]
B = B + [10 ** 10]

time = 0
count = -1
while time <= K:
    if A[0] <= B[0]:
        time += A.pop(0)
    else:
        time += B.pop(0)
    count += 1

print(count)
def iteraccumulate(l):
    from itertools import accumulate
    return list(accumulate(l))


def resolve():
    from bisect import bisect_right
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    aa = [0] + iteraccumulate(a)
    bb = iteraccumulate(b)
    ans = 0
    for index, i in enumerate(aa):
        j = bisect_right(bb, k - i)
        if i + bb[j - 1] <= k:
            ans = max(ans, index + j)
    print(ans)


if __name__ == '__main__':
    resolve()
n, m, k = map(int,input().split())
A = input().split()
B = input().split()
c = 0
for i in range(len(B)):
    if i < len(A):
        if k >= int(A[i]):
            k = k - int(A[i])
            c += 1
    if k >= int(B[i]):
        k = k - int(B[i])
        c += 1
print(c)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
num = N+M
ans = 0
for i in range(N):
    for j in range(M):
        total = sum(A[0:(i+1)]) + sum(B[0:(j+1)])
        if K >= total:
            if i+j+2 > ans:
                ans = i+j+2
print(ans)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

#1

import numpy as np
import bisect
acum=np.cumsum(a).tolist()
bcum=np.cumsum(b).tolist()

ans=0

for i,c in enumerate(acum):
    d=k-c
    if d<0:break
    j=bisect.bisect_right(bcum,d)-1
 
    ans=max(ans,(i+1)+(j+1))
print(ans)
n, m, k = map(int, input().split())
a =  list(map(int, input().split()))
b = list(map(int, input().split()))
timer = 0
cnt = 0
def append_float(tg_list):
  if len(tg_list) == 0:
    tg_list.append(float('inf'))
  return tg_list
while timer <= k:
  a = append_float(a)
  b = append_float(b)
  min_pop = min(a[0], b[0])
  if min_pop == a[0]:
    timer += a.pop(0)
    cnt += 1
  elif min_pop == b[0]:
    timer += a.pop(0)
    cnt += 1
print(cnt)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
 
sum = []
a,b = [0],[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])
  
for i in range(N+M+2):
  tmp = 0
  for j in range(i):
    if a[j]+b[i-j] < K:
      tmp = 1
      ans = i
      break
  if tmp == 0:
    break

print(ans)
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 0
 
while k >= 0:
  if len(a) == 0 and len(b) == 0:
    break;
  elif len(a) == 0:
    p = b.pop(0)
  elif len(b) == 0:
    p = a.pop(0)    
  else:
    p = a.pop(0) if a[0] > b[0] else b.pop(0)

  k -= p
  if  k >= 0:
    c += 1
  
print(c)
N,M,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))

from itertools import accumulate
from collections import deque
A=deque(list(accumulate(A)))
B=deque(list(accumulate(B)))
A.appendleft(0)
B.appendleft(0)
ans1=0
for i in range(N+1):
    if A[i]>K:
        ans1=i
        break
else:
    ans1=N
ans2=0
ans3=0
for i in range(ans1):
    while i+ans2<=M and A[ans1-i]+B[i+ans2]<=K:
        ans2+=1
    ans3=max(ans3,ans1+ans2-1)
print(ans3)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
acc = sum(B)
j = M - 1
if K >= acc + sum(A):
    print(M + N)
    exit()
ans = 0 if K < acc else M
for i in range(N):
    acc += A[i]
    if K >= acc:
        ans = max(ans, i + j + 2)
        continue
    else:
        while (K < acc) & (j > -1):
            acc -= B[j]
            j -= 1
        if K >= acc:
            ans = max(ans, i + j + 2)
print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.extend(b)

time = 0
count = 0
for x in a:
  if time > k:
    break
  time += x
  count += 1
print(count)
N, M, K = map(int,input().split())

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


for i in range(M):
    A.append(B[i])
    
A.sort()

ans = 0
count = 0

for i in range(N+M):
    if ans + A[i] <= K:
        ans += A[i]
        count += 1
    else:
        break
    
print(count)
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.append(a[i] + arui[i])
for i in range(M):
    brui.append(b[i] + brui[i])

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

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

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

cA = list(itertools.accumulate(A))
cB = list(itertools.accumulate(B))

#print(cA)
#print(cB)

ans = 0
for i in range(n):
    tmp = cA[-(i+1)]
    if tmp <= k:
        indb = bisect.bisect_left(cB, k - tmp)
        #print(indb)
        ans = max(ans, (n-i)+indb)
    
print(ans)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ruia=[0]
ruib=[0]
mx=0
for (i,j) in zip(a,range(n)):
  ruia.append(ruia[j]+i)

for (i,j) in zip(b,range(m)):
  ruib.append(ruib[j]+i)
ans=0
for i in range(n+1):
  if ruia[i] > k:
    break
  while ruib[j] > k - ruia[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()) )

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

for a in range(len(A)):
    if A[a]>k:
        break
    ans = max(ans, a+1)
    for b in range(len(B)):
        if A[a] + B[b] > k:
            break
        
        ans = max(ans, a+b+2)
        
print(ans)
import bisect
from itertools import accumulate

N , M , K = map(int , input().split())
a = list(map(int , input().split()))
b = list(map(int , input().split()))
a = list(accumulate(a))
b = list(accumulate(b))
a.insert(0,0)

ans = 0
for i in range(N + 1):
    if a[i] > K:
        break
    ans = max(ans , bisect.bisect_right(b, K - a[i]))
print(ans)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=a+b
c.sort()
i=0
sum=0
while sum<k:
  sum=sum+c[i]
  i=i+1
print(i-1)
N,M,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
X = sorted(A + B)
time = 0
cnt = 0
for i in range(len(X)):
    if K < X[i] + time:
        break
    else:
        time += X[i]
        cnt += 1
print(cnt)
n,m,k,*ab=map(int,open(0).read().split())
a=ab[:n]
b=ab[n:]
ans=0
i=0
j=0
while k>=0:
  if n==i:
    if m==j:
      break
    else:
      k-=b[j]
      j+=1
  elif m==j:
    k-=a[i]
    i+=1
  else:
    mini=a[i] if a[i]<b[j] else b[j]
    if a[i]>b[j]:
      j+=1
    else:
      i+=1
    k-=mini
  if k>=0:
    ans+=1
print(ans)
n,m,k =map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.append(10**9+1)
b.append(10**9+1)
cnt = 0
cnt2 = 0
mo = 0
for i in range(n+m):
  if a[cnt] >= b[cnt2]:
    mo += b[cnt2]
    if mo > k:
      print(cnt+cnt2)
      exit(0)
    cnt2+=1
  else:
    mo += a[cnt]
    if mo > k:
      print(cnt+cnt2)
      exit(0)
    cnt += 1
print(cnt+cnt2)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
S=sum(A)+sum(B)
count=len(A)+len(B)

for i in range(len(A)+len(B)):
  if S > K:
    if A[-1] >= B[-1]:
      S -= A[-1]
      count -= 1
    else:
      S -= B[-1]
      count -= 1

print(count)
def main():
    n, m, k = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = []
    for x in range(n+1):
        sumA = sum(A[0:x+1])
        for y in range(m+1):
            sumB = sum(B[0:y+1])
            if sumA + sumB <= k:
                C.append(sumA + sumB)
    print(C)
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, 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
N, M, K = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

ans = 0
for n in range(N):
    for m in range(M):
        if K < sum(A_list[:n+1]):
            print(ans)
            sys.exit()
        
        if K >= sum(A_list[:n+1])+sum(B_list[:m+1]):
            ans = max(ans, n+m+2)
        else:
            break
            
print(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()))
A=list(accumulate(a))
B=list(accumulate(b))

ans=0
for i in range(n):
    if k-A[i]>=0:
        c = bisect.bisect_right(B, k-A[i])
        ans = max(i+c+1,ans)
print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = n + m
while sum(a) + sum(b) > k:
    if len(a) == 0:
        a.append(0)
    if len(b) == 0:
        b.append(0)
    if sum(a) < sum(b):
        del b[-1]
    else:
        del a[-1]
    ans -= 1
print(ans)
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for _ in range(m):
    A.append(10 ** 9 + 1)
for _ in range(n):
    B.append(10 ** 9 + 1)
A.sort(reverse=True)
B.sort(reverse=True)
total = 0
count = 0
for i in range(n + m):
    time = min(A[-1], B[-1])
    if A[-1] == time:
        total += A.pop()
    elif B[-1] == time:
        total += B.pop()
    if total > k:
        break
    count += 1
print(count)
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])
print(a)
print(b)

totaltime = 0
count,j = 0, M

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

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

sa = list(itertools.accumulate(a))
sb = list(itertools.accumulate(b))

max = 0

for i in range(n + 1):
    j = m -1
    while j > 0:
        if (sa[i] + sb[j] <= k):
            if i + j > max:
                max = i + j
            break
        else:
            j -= 1
print(max)
n,m,k=list(map(int,input().split()))
A=list(map(int,input().split())) + [10**9+1]
B=list(map(int,input().split())) + [10**9+1]
time,ans = 0,0
a_idx,b_idx=0,0

while time < k and (a_idx != n or b_idx != m):
  if A[a_idx] <= B[b_idx] and a_idx < n:
    time += A[a_idx]
    a_idx += 1
    ans += 1
  elif A[a_idx] > B[b_idx] and b_idx < m:
    time += B[b_idx]
    b_idx += 1
    ans += 1
    
if time > k:
  print(ans-1)
else:
  print(ans)
a = input().split()
x = input().split()
y = input().split()
z = x + y
zz = []
zz = list(map(lambda i: int(i), z))
t = 0
for i in range(len(zz)):
  if t > int(a[2]):
    break
  t += sorted(zz)[i]
print(t)
from itertools import accumulate

n,m,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

la = [0] + list(accumulate(a))
lb = [0] + list(accumulate(b))

ans = 0
i = n
for j in range(m+1):
    while la[i]+lb[j] > k and i>=0:
        i -= 1
    ans = max(ans, i+j)

print(ans)
from collections import deque

N,M,K = map(int,input().split())
Ali = list(map(int,input().split()))
Bli = list(map(int,input().split()))

r = 0
s = 0
t = 0

for i in range(N):
  if Ali[i] <= K-t:
    r += 1
    t += Ali[i]
    
for i in range(M):
  if Bli[i] <= K-t:
    r += 1
    t += Bli[i]
    
for i in range(M):
  if Bli[i] <= K-t:
    s += 1
    t += Bli[i]
    
for i in range(N):
  if Ali[i] <= K-t:
    s += 1
    t += Ali[i]
    
print(max(r,s))
import bisect

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

a_sum = [0]*(n+1)
b_sum = [0]*(m+1)

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

ans = 0
for i in range(n+1):
  j = bisect.bisect(b_sum, k - a_sum[i]) - 1
  tmp = i + j
  ans = max(ans, tmp)

print(ans)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=sorted(a+b)
cnt=0
ans=0
flag=True
for i in c:
  cnt+=i
  if cnt>k:
    flag=False
    print(ans)
    break
  else:
    ans+=1
if flag:
  print(n+m)
import sys
# from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n, m, k = read()
	arr1 = read(); arr2 = read()
	for i in range(1, n):arr1[i] += arr1[i-1]
	for i in range(1, m):arr2[i] += arr2[i-1]
	i = 0; ans = 0
	while i < n and arr1[i] < k:
		tem = i + bisect(arr2, k-arr1[i])+1
		ans = max(ans, tem)
		i += 1
	print(ans)

	





		

if __name__ == "__main__":
	solve()
import bisect
from itertools import accumulate
n,m,k=map(int,input().split())
a=list(accumulate(map(int,input().split())))
b=list(accumulate(map(int,input().split())))
ans=0
for i,x in enumerate(a):
    y=k-x
    if y>0:
        j=bisect.bisect_right(b,y)
        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, 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
for i in range(N + 1):
  if K < a[i]:
    break
  else:
    res = K - a[i]
  #print(res)
  num = 0
  j = 0
  while j <= M and b[j] <= res:
    #print("b:",b[j])
    j += 1
    # print(j)
  num = i + (j - 1)
  if output <= num:
    output = num
print(num)