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


index = 0
index2 = 0
stackedTime = 0

while(index<N and stackedTime + A[index] <= K):
  stackedTime += A[index]
  index += 1

while(index2 < M and stackedTime + B[index2] <= K):
  stackedTime += B[index2]
  index2 += 1

maxBook = index + index2
for i in range(N):
  if(index == 0 or index2 == M):
    break
  index -= 1
  stackedTime -= A[index]
  while(index2 < M and stackedTime + B[index2] <= K):
    stackedTime += B[index2]
    index2 += 1

  maxBook = max(maxBook, index + index2)

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

SA = [0]*(N+1)
SB = [0]*(M+1)
T = 0


ans = 0

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

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

for i in range(N+1):
    if SA[i] > K:
        break
    id = bisect.bisect_right(SB, K - SA[i]) - 1
    ans = max(ans, i + id)


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[-1])
for i in range(m):
    bb.append(b[i]+bb[-1])
ans = 0
j = m
for i in range(n+1):
    r = k - aa[i]
    while bb[j] > r and j >= 0:
        j -= 1
    if j >= 0:
        ans = max(ans, i+j)
print(ans)
from itertools import accumulate, permutations

import bisect
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

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

ans = 0
for i in range(N+1):
    a = A[i]
    if a > K:
        break
    r = K - a
    j = bisect.bisect(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()))

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

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

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

ac = [0]
bc = [0]

for i in range(N):
    ac.append(ac[i] + A[i])
for i in range(M):
    bc.append(bc[i] + B[i])

ans = 0
j = M

for i in range(N+1):
    if ac[i] > K:
        break
    while bc[j] > K - ac[i]:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
import bisect

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
for i in range(n+1):
  if acum1[i]>k:
    break
  ans=max(ans,i+bisect.bisect_right(acum2,k-acum1[i])-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=0
j=m
for i in range(n+1):
    if a[i]>k:
        break
    time=a[i]+b[j]
    while time>k:
        j-=1
        time=a[i]+b[j]
    ans=max(ans,i+j)
print(ans)
'''ABC172 C'''
import numpy as np
n,m,k = map(int,input().split())
a = np.array([int(i) for i in input().split()], dtype='int64')
b = np.array([int(i) for i in input().split()], dtype='int64')

a_c = np.zeros(n+1,dtype='int64')
a_c[1:] = np.cumsum(a)

b_c = np.zeros(m+1,dtype='int64')
b_c[1:] = np.cumsum(b)

a_c = a_c[a_c <= k]
b_c = b_c[b_c <= k]
ans = 0
for i,ai in enumerate(a_c):
    n = np.searchsorted(b_c, k - ai, side = 'right')
    ans = max(i + n-1, ans)
print(ans)
n,m,k = list(map(int,input().split(" ")))
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
cnt = 0
ans = 0
j = m
t = sum(b)

for i in range(n+1):
    while j>0:
        if t>k: #aのみの場合の処理が足りない（常にjでスキップされてしまう）
            j -= 1
            t -= b[j]
        else:break
    if t<=k:ans = max(ans,i+j)
    if i==n:break
    t += a[i]
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:
    break
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

print(ans)
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_sum=[]
b_sum=[]
a_sum.append(0)
b_sum.append(0)
for i in range(n):
    a_sum.append(a_sum[i]+a[i])
for j in range(m):
    b_sum.append(b_sum[j]+b[j])
ans=0
for x in range(n+1):
    timecount=k-a_sum[x]
    if timecount>=0:
        y=bisect.bisect_right(b_sum,k-a_sum[x])-1
        ans=max(x+y,ans)
    else:
        break
print(ans)
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

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

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

ri,sum=-1,0
for i in range(M):
    if sum+B[i]<=K:
        ri=i
        sum+=B[i]
    else :
        break

sum2,ans=0,ri+1
for i in range(N):
    sum2+=A[i]
    if sum2>K:
        break
    while ri>=0 and sum2+sum>K:
        sum-=B[ri]
        ri-=1
    ans=max(ans,i+1+ri+1)
print(ans)
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

t = sum(B)

# しゃくとり法
res = 0
j = m
for i in range(n + 1):
    while j > 0 and t > k:
        j -= 1
        t -= B[j]
    if t > k:
        break
    res = max(res, i + j)
    if i == n: break
    t += A[i]

print(res)
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,1):
    A[i]=A[i-1]+A[i]
for i in range(1,M+1,1):
    B[i]=B[i-1]+B[i]

ans = 0
for i in range(0,N+1,1):
    j = bisect_right(B,K-A[i])-1
    if K-A[i]>=0:
        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()))
ra = [0] * (n + 1)
rb = [0] * (m + 1)
for i in range(n):
    ra[i + 1] = a[i] + ra[i]

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

ans = 0
for i in range(n + 1):
    zan = k - ra[i]
    if zan < 0:
        break
    rbi = bisect.bisect_right(rb, zan) - 1
    if rbi < 0:
        rbi = 0
    ans = max(ans, i + rbi)
print(ans)
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0 and ax>k:continue
    r=max(r,i+bis)
print(r)
N, M , K = map(int, input().split())
X = [0] + list(map(int, input().split()))
Y = list(map(int, input().split()))
R,sY,j,t= 0,sum(Y),M,0
for i in range(N+1):
    t += X[i]
    if t > K: break
    while j and sY+t > K:
        j-=1
        sY -= Y[j]
    R = max(R, j+i)
print(R)
N,M,K = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
B = list(map(int,input().split(" ")))

time_A = [0]*(N+1)
time_B = [0]*(M+1)

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

ans = 0
l = M

for k in range(N+1):
    if time_A[k] > K:
        break
    while time_A[k] + time_B[l] > K:
        l -= 1
    ans = max(ans,k+l)

print(ans)
import numpy as np
import bisect
N,M,K= map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
if A[0]>K and B[0]>K:print(0);exit()

Asum=[0]
for i in range(N):
  if Asum[-1]+A[i]<=K:
    Asum.append(Asum[-1]+A[i])  
  else:break
Bsum=[0]
for j in range(M):
  if Bsum[-1]+B[j]<=K:
    Bsum.append(Bsum[-1]+B[j])
  else:break

C=[]
for i in range(len(Asum)):
  C.append(bisect.bisect(Bsum,K-Asum[i])+i-1)
print(max(C))
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]*N
b=[0]*M
a[0]=A[0]
b[0]=B[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]
book=bisect_right(b,K)
for i in range(N):
    if a[i]>K:
        break
    j=bisect_right(b,K-a[i])
    book=max(book,(i+1)+j)
print(book)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0]*(N+1), [0]*(M+1)
for i in range(N):
	a[i+1] = a[i] + A[i] 
for i in range(M):
	b[i+1] = b[i] + B[i]
 
ans, j = 0, M
for i in range(N + 1):
	if a[i] > K:
		break
	while b[j] > K - a[i]:
		j -= 1
	ans = max(ans, i + j)
print(ans)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
a,b = [0],[0]
for i in range(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
 
ans,j = 0,M
for i in range(N+1):
    if a[i]>K:
        break    
    while b[j]>K-a[i]:
        j -= 1    
    ans = max(ans,i+j)
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a=[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)
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)
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)
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()), initial=0)]
print(max(i - 1 + 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()))

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 = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

WA = [0] * (N + 1)
WB = [0] * (M + 1)
for i in range(N):
    WA[i + 1] = WA[i] + A[i]
for j in range(M):
    WB[j + 1] = WB[j] + B[j]
ma = 0
last = False
for i in range(0, N + 1):
    if WA[i] > K:
        break
    t = K - WA[i]
    j = bisect.bisect(WB, t)
    ma = max(ma, i + j - 1)

print(ma)
n,m,k,*a=map(int,open(0).read().split())
s=sum(a[:n])
x=i=j=n
a+=k,
while~i:
 while s+a[j]<=k:s+=a[j];j+=1
 if s<=k:x=max(x,i+j)
 i-=1;s-=a[i]
print(x-n)
n,m,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
ca=[0]*(n+1)
ca[1]=a[0]
for i in range(n):
  ca[i+1]=ca[i]+a[i]
cb=[0]*(m+1)
cb[1]=b[0]
for i in range(m):
  cb[i+1]=cb[i]+b[i]
j=m
ans=0
for i in range(n+1):
  t=ca[i]
  while j>=0:
    if t+cb[j]>k:
      j-=1
    else:
      ans=max(ans,i+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)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

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

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

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

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

dpA = [0]*(N+1)
dpB = [0]*(M+1)

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

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

ans = 0
for i in range(N+1):
    if dpA[i] > K:
        continue
    indexB = bisect.bisect_right(dpB, K - dpA[i])
    ans = max(ans, i + indexB - 1)

print(ans)
import bisect
N,M,K = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A = [0]*(N+1)
B = [0]*(M+1)
for i in range(N):
    A[i+1] = A[i] + a[i] 
for i in range(M):
    B[i+1] = B[i] + b[i] 

possible = [0]
for i in range(N+1):
    ans = i
    nokori = K - A[i]
    if nokori < 0:
        break
    else:
        j = bisect.bisect_right(B,nokori)
        ans += j-1
        possible.append(ans)

print(max(possible))
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_cnt = m
for a_cnt in range(n+1):
    if a[a_cnt] > k:
        continue
    while a[a_cnt] + b[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)
print(ans)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
A.insert(0,0)
B.insert(0,0)
import numpy as np
A=np.array(A).cumsum()
B=np.array(B).cumsum()

for i in range(N+1):
  d=K-A[i]
  for j in reversed(range(M+1)):
    if d-B[j]>=0:
      if c<i+j:
        c=i+j
      M=j
      break
print(c)
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 ruisekiwa(List):
    for i in range(1, len(List)):
        List[i] += List[i - 1]
    return List

arui = ruisekiwa(a)
brui = ruisekiwa(b)
arui.insert(0, 0)
brui.insert(0, 0)
ans = 0

for i in range(n + 1):
    if arui[i] > k:
        break
    j = bisect_right(brui, k - arui[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()))


import bisect

cum_a = [0]
for a in A:
    cum_a.append(cum_a[-1] + a)

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

ans = 0
for i in range(n + 1):
    t = cum_a[i]
    if t <= k:
        bnum = i
    else:
        bnum = 0
    if t <= k:
        idx = bisect.bisect_right(cum, k - t)
        bnum += idx - 1
    ans = max(ans, bnum)
print(ans)
import bisect
def LI():
  return list(map(int,input().split()))

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

cumA = [0]
for a in A:
  cumA.append(cumA[-1]+a)

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

res = 0
for i in range(N+1):
  cuma = cumA[i]
  if cuma > K: continue
  rem = K-cuma
  deskb = bisect.bisect_right(cumB, rem)-1

  res = max(res, i+deskb)

print(res)
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_acc =[0] + list(accumulate(A))
b_acc =list(accumulate(B))

ans = 0

for an in range(len(a_acc)):
    rem = K - a_acc[an]
    if rem < 0:
        break
    
    bn  = bisect.bisect_right(b_acc, rem)

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

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

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

ans = 0
for i in range(n+1):
    if sa[i] > k:
        break
    bi = bisect.bisect_right(sb, k-sa[i])-1
    ans = max(ans, i + bi)
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)
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()))

ans=0
for i in range(1,n+1):
  A[i]+=A[i-1]


for j in range(1,m+1):
  B[j]+=B[j-1]


b_cnt=m
for a_cnt in range(n+1):
  if A[a_cnt]>k:
    continue
  while A[a_cnt]+B[b_cnt]>k:
    b_cnt-=1 

  ans=max(ans,a_cnt+b_cnt)
print(ans)
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, K = mapint()
As = [0]+list(mapint())
Bs = [0]+list(mapint())
from itertools import accumulate
from bisect import bisect_right
ac = list(accumulate(As))
bc = list(accumulate(Bs))

ans = 0
for i in range(N+1):
    now = ac[i]
    rest = K-now
    if rest<0:
        break
    idx = bisect_right(bc, rest)
    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()))

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 = k + 1
  for i in range(p + 1):
    if min(i, n) + min(p - i, m) < p:
      continue
    best = min(best, As[i] + Bs[p - i])
  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 = [0]*(N+1)
b = [0]*(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]

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

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

j = M

for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    ans = max(ans, i+j)
print(ans)
import numpy as np

n, m, k = map(int, input().split())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

a = [0]
b = [0]

a = np.append(a, np.cumsum(A))
b = np.append(b, np.cumsum(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)
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sa = [0 for i in range(n+1)]
sb = [0 for i in range(m+1)]

c = 0

for i in range(n):
  c += a[i]
  sa[i+1] = c
c = 0
for i in range(m):
  c += b[i]
  sb[i+1] = c
ans = 0
# if k >= sum(a)+sum(b):
#   print (n+m)
#   exit()
for i in range(n+1):
  x = k - sa[i]
  if x < 0:
    continue
  y = bisect.bisect_right(sb,x)
  y += i
  ans = max(ans, y-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 range(n):
    a.append(a[i] + A[i])
for i in range(m):
    b.append(b[i] + B[i])

ans = 0

for i in range(n + 1):
    if a[i] > k:
        break
    while  a[i] + b[m] > k:
        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()))
cuma = [0]
cumb  = [0]
for a in A:
    cuma.append(cuma[-1] + a)
for b in B:
    cumb.append(cumb[-1] + b)
from bisect import bisect_left
ans = 0
for i in range(n+1):
    if k < cuma[i]: continue
    idx = bisect_left(cumb, k - cuma[i] + 1)
    ans = max(ans, i + idx - 1)
for j in range(m+1):
    if k < cumb[j]: continue
    idx = bisect_left(cuma, k - cumb[j] + 1)
    ans = max(ans, j + idx - 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 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 b[j] > K - a[i]:
        j -= 1
    ans = max(i + j, ans)

print(ans)
from bisect import bisect
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
a = [0] * (N+1)
b = [0] * (M+1)
for i in range(N):
    a[i+1] = a[i] + A[i]
for i in range(M):
    b[i+1] = b[i] + B[i]
ans = 0
for i in range(N+1):
    tmp = K - a[i]
    if tmp < 0:
        break
    ans = max(ans, i + bisect(b, tmp) - 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 idx, num in enumerate(A):
    a.append(a[idx] + num)
for idx, num in enumerate(B):
    b.append(b[idx] + num)

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 numpy as np
import bisect
n,m,k=map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
A=np.cumsum(np.array([0]+a))
B=np.cumsum(np.array(b))
ans=0
for i in range(n+1):
    if A[i]>k:
        break
    t=k-A[i]
    tmp=bisect.bisect_right(B,t)
    ans=max(ans, i+tmp)
print(ans)
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
arr1, arr2 = [0], [0]
for i in range(n):
	arr1.append(arr1[i] + A[i])
for i in range(m):
	arr2.append(arr2[i] + B[i])

count = 0
j = m
for i in range(n + 1):
	if arr1[i] > k:
		break
	while arr2[j] > k - arr1[i]:
		j -= 1
	count = max(count, i + j)
print(count)