program main
implicit none
	integer(8):: N,i,j,t,K,X,M,o,p,q,a1,b1
	integer(8),dimension(1:2*100000)::A=1000000000,B=1000000000,C
	read *, N,M,K
    read(*,*) (A(i), i = 1, N)
    read(*,*) (B(i), i = 1, M)

   	if(N>=M)then
    q=N
    else
    q=M
    end if
    a1=1
    b1=1
    t=0
	do i=1,q
    	if(t+A(a1)+b(b1)<=K)then
        t=t+A(a1)+B(b1)
        a1=a1+1
        b1=b1+1
	    else if(t+A(a1)<=K)then
        t=t+A(a1)
        a1=a1+1
        else if(t+b(b1)<=K)then
        t=t+b(b1)
        b1=b1+1
		end if
    end do
        print'(I0)',a1+b1-2
end program main

