peterverebics/CodeNet_Python_118 huggingface dataset:
from bisect import *

N,M,K,*f = map(int, open(0).read().split())
A = f[:N]
B = f[N:]
csa = [0]
ans = 0
for i in range(N):
    csa.append(csa[i]+A[i])
csb = [0]
for i in range(M):
    csb.append(csb[i]+B[i])
for i in range(N+1):
    if csa[i] <= K:
        bs = bisect_right(csb,K-csa[i])
        ans = max(ans,i+bs-1)
    else:
        break
print(ans)
import sys
from bisect import bisect
from itertools import accumulate

n, m, k, *ab = map(int, sys.stdin.buffer.read().split())
aaa = [0] + ab[:n]
bbb = [0] + ab[n:]
acc = list(accumulate(aaa))
bcc = list(accumulate(bbb))

ans = 0
for i in range(n + 1):
    r = k - acc[i]
    if r < 0:
        break
    j = bisect(bcc, 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()))

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

ans = 0
tmp = m
for i in range(n+1):
    for j in range(tmp+1)[::-1]:
        if s_a[i] + s_b[j] <= k:
            ans = max(ans, i+j)
            tmp = j
            break
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
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]
  
import bisect

ans = 0
for i in range(len(A)):
  rest = K - A[i]
  if rest < 0:
    continue
  if ans < i:
    ans = i
  b_read = bisect.bisect_right(B, rest)
  if ans < i + b_read - 1:
    ans = i + b_read - 1
    
print(ans)
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
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]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))
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 accumulate
from bisect import bisect_left
 
n,m,k=map(int,input().split())
a=list(accumulate([0]+list(map(int,input().split()))))
b=list(accumulate([0]+list(map(int,input().split()))))
#print(b)
mx=0
for i in range(n+1):
  if a[i]>k:continue
  #print('a[i];'+str(a[i]))
  idx=min(bisect_left(b,k-a[i]),m)
  #print(idx)
  if b[idx]>k-a[i]:idx-=1
  if a[i]+b[idx]>k:continue
  mx=max(mx,i+idx)
print(mx)
import bisect

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

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

a = [0] + a
b = [0] + b

ans = 0

for i in range(n+1):
    can = k - a[i]
    if can < 0:
        break
    j = bisect.bisect_right(b, can)
    ans = max(ans, i+j-1)
print(ans)
import bisect
N,M,K=[int(s) for s in input().split()]
A=[int(s) for s in input().split()]
B=[int(s) for s in input().split()]
Asum=[0 for i in range(N+1)]
Bsum=[0 for i in range(M+1)]
for i in range(N):
  Asum[i+1]=Asum[i]+A[i]
for i in range(M):
  Bsum[i+1]=Bsum[i]+B[i]
ans=[0 for i in range(N+1)]
t=bisect.bisect_right(Bsum,K)-1
ans[0]=t
for i in range(1,N+1):
  if Asum[i]>K:
    break
  while Bsum[t]+Asum[i]>K:
    t-=1
  ans[i]=i+t
print(max(ans))
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

tmpA = [0]*(N+1)
tmpB = [0]*(M+1)
ans = 0

import bisect
for i in range(1,N+1):
    tmpA[i] = tmpA[i-1] + A[i-1]
for i in range(1,M+1):
    tmpB[i] = tmpB[i-1] + B[i-1] 
for i in range(N+1):
    tmp = tmpA[i]
    if tmp > K:
        break
    index = bisect.bisect_right(tmpB,K-tmp)
    ans = max(i+index-1,ans)
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()))

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

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 itertools

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

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

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

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

    result = 0
    for i in range(n+1):
        tmp = k - a[i]
        if tmp < 0:
            continue
        tmpNum = i + bisect_right(b, tmp) - 1
        if tmpNum > result:
            result = tmpNum

    print(result)       


if __name__ == "__main__":
    main()
import bisect
N, M, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]

A_sum = [0]
a_sum = 0
for a in A:
  a_sum += a
  A_sum.append(a_sum)
B_sum = [0]
b_sum = 0
for b in B:
  b_sum += b
  B_sum.append(b_sum)

ans = 0
for i in range(N+1):
  b_time = K - A_sum[i]
  if b_time < 0:
    break
  idx = bisect.bisect_right(B_sum, b_time)
  ans = max(ans, i + idx-1)
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
t, ans = sum(B), 0
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()))

At = [0]*(N+1)
Bt = [0]*(M+1)

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

j = M
ans = 0
for i in range(N+1):
  if At[i] > K:
    break
  while At[i] + Bt[j] > K:
    j = j - 1
  if ans < i + j:
  	ans = i+j 

print(ans)
# coding: utf-8
# Your code here!
import bisect

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

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

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


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

ans=0
for i in range(N+1):
    target=K-sum_A[i]
    if target>=0:
        j=bisect.bisect(sum_B,target)
        ans=max(ans,i+j-1)

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

N,M,K=map(int,input().split())
A=list(accumulate([0]+[int(x) for x in input().split()]))
B=list(accumulate([0]+[int(x) for x in input().split()]))

m=0
for i in range(0,N+1):
  if K<A[i]:
    break
  m=max(m,i+bisect_right(B,K-A[i])-1)

print(m)
N,M,K = list(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 accumulate
from bisect import bisect

n, m, k = map(int, input().split())
(*a,) = accumulate(map(int, input().split()))
(*b,) = accumulate(map(int, input().split()))
a = (0,) + tuple(i for i in a if i <= k)
b = tuple(i for i in b if i <= k)
print(max(i + bisect(b, k - a[i]) for i in range(len(a))))
import bisect
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ac = [0]*(N+1)
bc = [0]*(M)
bc[0] = b[0]
for i,val in enumerate(a):
    ac[i+1] = ac[i] + val
for i,val in enumerate(b[1:]):
    bc[i+1] = bc[i] + val
res = 0
for i,val in enumerate(ac):
    if val > K:
        break
    rest = K-val
    idx = bisect.bisect_right(bc, rest)
    if idx+i > res:
        res = idx+i
print(res)
import numpy as numpy 
import bisect as bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
a.insert(0,0)
ali = numpy.cumsum(a)
bli = numpy.cumsum(list(map(int,input().split())))
a = [0]
for i in range(n+1):
    if ali[i] > k:
        break
    b = bisect.bisect_right(bli,k-ali[i])
    a.append(i+b)
print(max(a))
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
#total = 0
books = 0
#i = 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])

l = m

for i in range(n+1):
    if A[i]>k:
        break
    while B[l]>k-A[i]:
        l -= 1
    books = max(books,i+l)

print(books)
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):
    d += a[i]
    c.append(d)

e = [0]
f = 0
for i in range(m):
    f += b[i]
    e.append(f)


ans = 0
j = m
for i in range(n+1):
    if c[i] > k:
        break
    else:
        while c[i] + e[j] > k:
            j -= 1
    ans = max(i + j,ans)

print(ans)
from sys import stdin
from sys import setrecursionlimit
from itertools import accumulate
import bisect

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

aa = [0]+list(accumulate(a))
bb = [0]+list(accumulate(b))
ma = 0

for i,j in  enumerate(aa):
    if j > k:
        break
    nowa = i
    nowb = bisect.bisect(bb,k-j)-1
    ma = max(ma,nowa+nowb)

print(ma)
a,b,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

from itertools import accumulate

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

ans = 0
num = b
for i in range(a+1):
    if A[i] > k:
        continue
    while True :
        if A[i] + B[num] > k:
            num -=1
        else:
            ans = max(ans,i+num)
            break
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
anss = []
for i in range(1+N):
    if a[i] > K:
        break
    while 1:
        if a[i] + b[j] <= K:
            break
        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()))
A.insert(0, 0)
B.insert(0, 0)
for i in range(1, N+1):
    A[i] += A[i-1]
for i in range(1, M+1):
    B[i] += B[i-1]
ans = 0
for i in range(N+1):
    sub = 0
    if A[i] <= K:
        sub += i
        sub += bisect.bisect_right(B, K-A[i])-1
    ans = max(sub, ans)
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)
n,m,k = map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

aa = [0]
bb = [0]

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

for i in range(m):
	bb.append(b[i]+bb[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(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])
  
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)
# 尺取法ver

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

asum, bsum = [0], [0]
for i in range(n):
  if k < a[i] + asum[i]:
    break
  asum.append(a[i] + asum[i])
for i in range(m):
  if k < b[i] + bsum[i]:
    break
  bsum.append(b[i] + bsum[i])

ans = 0
b_count = len(bsum)-1
for a_count in range(len(asum)):
  while asum[a_count] + bsum[b_count] > k:
    b_count -= 1
  ans = max(ans, a_count + b_count)
print(ans)
from itertools import accumulate
n, m, k = map(int, input().split())
Acum = [0]+list(accumulate(map(int, input().split())))
Bcum = [0]+list(accumulate(map(int, input().split())))

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

C = A[::-1] + B

right = 0
size = 0
ans = 0
for left in range(N+M):
    while right < (N+M) and size+C[right] <= K:
        size += C[right]
        right += 1
    if left <= N and N <= right:
        ans = max(ans, (right-left))
    if left == right:
        right += 1
    else:
        size -= C[left]

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)
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(accumulate(A))
b = list(accumulate(B))

ans = 0
for i in range(N):
    tmp = a[i]
    if tmp <= K:
        j = bisect_right(b, K-tmp)
        ans = max(ans, i+j+1)
ans = max(ans, bisect_right(b, K))
print(ans)
from itertools import accumulate
from bisect import bisect

n, m, k = map(int, input().split())
a = accumulate(map(int, input().split()), initial=0)
b = [*accumulate(map(int, input().split()))]
print(max(i + bisect(b, k - x) for i, x in enumerate(a) if x <= k))
N, M, 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(N):
    Asum.append(Asum[-1]+A[i])
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    
m=0
j=M

for i in range(len(Asum)):
    if Asum[i]>K:
        break
    while Asum[i]+Bsum[j]>K:
        j-=1
    if m<i+j:
        m=i+j
        
print(m)
N, M, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = [0]+list(map(int, input().split()))
import itertools
A_cs = list(itertools.accumulate(A))
B_cs = list(itertools.accumulate(B))

total = 0
j = len(B)-1
for i in range(len(A_cs)):
    while (j >= 0):
        if A_cs[i] + B_cs[j] <= K:
                total = max(total,i + j)
                break
        j -= 1

print(total)
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)
#!/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 b[j] + a[i] > K:
        j -= 1
    ans = max(ans, i + j)
print(ans)
def resolve():
    import numpy as np

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

    A = np.insert(np.cumsum(A), 0, 0)
    B = np.insert(np.cumsum(B), 0, 0)

    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)

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

As = [0] * (n + 1)
Bs = [0] * (m + 1)
for i in range(n):
  As[i + 1] = A[i] + As[i]
for i in range(m):
  Bs[i + 1] = B[i] + Bs[i]

l = 0
r = n + m + 1
while r - l > 1:
  p = (l + r) // 2
  best = min(
    As[i] + Bs[p - i] for i in range(p + 1)
    if min(i, n) + min(p - i, m) == p
  )
  if best <= k:
    l = p
  else:
    r = p
print(l)
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()))

aa,bb=[0],[0]
for i in range(n):
  aa.append(aa[i]+a[i])
for i in range(m):
  bb.append(bb[i]+b[i])
ans,j=0,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)
import bisect
import numpy

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

cost_a = numpy.insert(numpy.cumsum(a), 0, 0)
cost_b = numpy.insert(numpy.cumsum(b), 0, 0)

ans = 0
j =  len(cost_b) -1
for i in range(len(cost_a)):
    for j in range(j, -1, -1):
        if cost_a[i] + cost_b[j] <= k:
            ans  = i + j if ans < i + j else ans
            break
print(ans)
N,M,K=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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


res = bisect.bisect_right(B,K)

for i in range(N):
    if K >= A[i]:
        j=bisect.bisect_right(B,K-A[i])
        res=max(res, i+1+j)

print(res)
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_ac=[0]
for i in range(1,n+1):
  a_ac.append(a_ac[i-1]+a[i-1])

b_ac=[0]
for i in range(1,m+1):
  b_ac.append(b_ac[i-1]+b[i-1])

#print(a_ac)
#print(b_ac)

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

aa = [0]
bb = [0]
for i in range(n):
    aa.append(aa[-1]+a[i])
for i in range(m):
    bb.append(bb[-1]+b[i])
c = m
ans = 0
for i in range(n+1):
    u = k - aa[i]
    for j in range(c, -1, -1):
        if bb[j] <= u:
            ans = max(ans, i+j)
            c = j
            break
print(ans)
import itertools

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

acc_A = [0]+list(itertools.accumulate(A))
acc_B = [0]+list(itertools.accumulate(B))
    
ans, j = 0, m
for i in range(n+1):
    if acc_A[i] > k:
        break
    while acc_A[i] + acc_B[j] > k:
        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()))
S = [0]*N
T = [0]*M
S[0] = A[0]
for k in range(1,N):
    S[k] = S[k-1] + A[k]
T[0] = B[0]
for k in range(1,M):
    T[k] = T[k-1] + B[k]

ans = bisect.bisect_right(T,K)
for k in range(N):
    if K-S[k] >= 0:
        ans = max(ans,k+1+bisect.bisect_right(T,K-S[k]))
print(ans)
n, m, k = map(int, input().split())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))

a_sum = [0]
b_sum = [0]
for i in range(1, n+1):
  a_sum.append(a_sum[i-1] + an[i-1])
for j in range(1, m+1):
  b_sum.append(b_sum[j-1] + bn[j-1])

idx = len(bn)
ans = 0
for i in range(n+1):
  while a_sum[i] + b_sum[idx] > k:
    idx -= 1
    if idx == -1:
      break
  if idx == -1:
    break
  ans = max(ans, i + idx)

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

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


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

  while A[a_count] + B[b_count] > K:
    b_count -= 1

  ans = max(ans, a_count + b_count)
print(ans)
N, M, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i 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(len(a)):
    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, 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
import itertools
N, M, K = [int(_) for _ in input().split()]
A = list(itertools.accumulate([0] + [int(_) for _ in input().split()]))
B = list(itertools.accumulate([0] + [int(_) for _ in input().split()]))
ans = 0
for i, a in enumerate(A):
    if a > K:
        break
    ans = max(ans, i + bisect.bisect(B, K - a) - 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])

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 i in range(n):
    a.append(a[i]+a_[i])

b = [0]
for i in range(m):
    b.append(b[i]+b_[i])

j = m
ans = 0
for i in range(n+1):
    if a[i] > k:
        break
    while 1:#b[j] > k - a[i]:
        if b[j] <= k - a[i]:
            break
        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()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
    a += A[i]
    Asum.append(a)
for i in range(M):
    b += B[i]
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
        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])
count = 0
j = M
for i in range(N + 1): 
  if a[i]>K:
    break
  while b[j]+a[i]> K :
    j -= 1
  count = max(count, i+j)
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])
  
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)
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import itertools
N,M,K=MI()
A=[0]+LI()
B=[0]+LI()
A=list(itertools.accumulate(A))
B=list(itertools.accumulate(B))
j=M
ans=0
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)