CodeEff/ECCO huggingface dataset:
# Original solution
N, M, K = list(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[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = 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)

# Optimized solution
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)
# Original solution
N, M, K = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0]
brui = [0]
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)

# Optimized solution
N, M, K = list(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[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]


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

print(ans)
# Original solution
import sys
from collections import deque


def _tsundoku(n, m, k, a, b):
    # print(f'{a=}')
    # print(f'{b=}')
    a_len = len(a)
    b_len = len(b)

    ans = [0, 0, 0]

    L = []
    d = deque()
    d.append((0, 0, 0))
    while d:
        # print(d, L)
        a_readed, b_readed, t = d.popleft()
        if not (a_len > a_readed and t + a[a_readed] <= k) and not (b_len > b_readed and t + b[b_readed] <= k):
            # print(a_readed, b_readed, t)
            L.append(a_readed + b_readed)
        else:
            if a_len > a_readed and t + a[a_readed] <= k:
                d.append((a_readed + 1, b_readed, t + a[a_readed]))
            if b_len > b_readed and t + b[b_readed] <= k:
                d.append((a_readed, b_readed + 1, t + b[b_readed]))
    ans = max(L)
    return ans

def tsundoku(f):
    readline = f.readline
    n, m, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)

def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys
from itertools import accumulate


def _tsundoku(n, m, k, a, b):
    a_temp = tuple(accumulate(a, initial=0))
    b_temp = tuple(accumulate(b, initial=0))

    ans = 0
    b_index = m
    for a_index in range(n + 1):
        if a_temp[a_index] > k:
            break
        while a_temp[a_index] + b_temp[b_index] > k:
            b_index -= 1
        else:
            ans = max(ans, a_index + b_index)
    return ans


def tsundoku(f):
    readline = f.readline
    n, m, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    b = list(map(int, readline().split()))

    return _tsundoku(n, m, k, a, b)


def main():
    ans = tsundoku(sys.stdin.buffer)
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    total_T_in_A = [0] * (N+1)
    total_T_in_A[1] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

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

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

    result = 0
    for i in range(N+1):
        # A から i 冊読むときにかかる時間
        i_A_T = total_T_in_A[i]
        
        if K < i_A_T:
            continue

        if K == i_A_T:
            result = max(result, i)
            continue

        rem_T = K - i_A_T

        # total_T_in_B は累積和を格納した、ソート済の配列
        # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
        first = total_T_in_B[0]
        last = total_T_in_B[M-1]
        if rem_T < first:
            result = max(result, i)
            continue
        if last <= rem_T:
            result = max(result, i + M)
            continue

        # assume that first <= rem_T <= last
        first_i = 0
        last_i = M - 1
        while first_i < last_i:
            if abs(last_i - first_i) == 1:
                break
            mid_i = (first_i + last_i) // 2
            if rem_T < total_T_in_B[mid_i]:
                last_i = mid_i
            else:
                first_i = mid_i
        result = max(result, i + first_i + 1)

    print(result)

main()


# Optimized solution
def main():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    total_T_in_A = [0] * (N+1)
    total_T_in_A[1] = A[0]
    total_T_in_B = [0] * M
    total_T_in_B[0] = B[0]

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

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

    result = 0
    for i in range(N+1):
        # A から i 冊読むときにかかる時間
        i_A_T = total_T_in_A[i]
        
        if K < i_A_T:
            continue

        if K == i_A_T:
            result = max(result, i)
            continue

        rem_T = K - i_A_T

        # total_T_in_B は累積和を格納した、ソート済の配列
        # B_i <= rem_T < B_i+1 となるような B_i を二分探索によって探す
        first = total_T_in_B[0]
        last = total_T_in_B[M-1]
        if rem_T < first:
            result = max(result, i)
            continue
        if last <= rem_T:
            result = max(result, i + M)
            continue

        # assume that first <= rem_T <= last
        first_i = 0
        last_i = M - 1
        while first_i < last_i:
            if abs(last_i - first_i) == 1:
                break
            mid_i = (first_i + last_i) // 2
            if rem_T < total_T_in_B[mid_i]:
                last_i = mid_i
            else:
                first_i = mid_i
        result = max(result, i + first_i + 1)

    print(result)

main()
# Original solution
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=list(map(int,input().strip("\n").split()))
  A=deque()
  mapA=list(map(int,input().strip("\n").split()))
  for a in mapA:
    A.append(a)
  B=deque()
  mapB=list(map(int,input().strip("\n").split()))
  for b in mapB:
    B.append(b)
  #A=list(map(int,input().strip("\n").split()))
  #B=list(map(int,input().strip("\n").split()))
#  A.append(10**9+1)
#  B.append(10**9+1)

  #def dfs(a,b,k,s):
  def dfs(A,B,k,s):
    if k<0:
      return s-1
    if k==0:
      return s
    ansA=s
    ansB=s
    if len(A)>0:
      x=copy.deepcopy(A)
      y=copy.deepcopy(B)
      tmp=x.popleft()
      ansA=dfs(x,y,k-tmp,s+1)
    #if a<n:
    #  ansA=dfs(a+1,b,k-A[a],s+1)
    #else:
    #  ansA=s
    if len(B)>0:
      #print(A)
      x=copy.deepcopy(A)
      y=copy.deepcopy(B)
      tmp=y.popleft()
      ansB=dfs(x,y,k-tmp,s+1)
    #if b<m:
    #  ansB=dfs(a,b+1,k-B[b],s+1)
    #else:
    #  ansB=s
    return max(ansA,ansB)

  x=copy.deepcopy(A)
  y=copy.deepcopy(B)
  ans=dfs(x,y,k,0)
  #ans=max(dfs(1,0,k-A[0],1),dfs(0,1,k-B[0],1))
  print(ans)


# Optimized solution
import sys
from collections import deque
import copy
sys.setrecursionlimit(2147483647)
input = sys.stdin.readline

if __name__ == '__main__':
  n,m,k=list(map(int,input().strip("\n").split()))
  A=list(map(int,input().strip("\n").split()))
  B=list(map(int,input().strip("\n").split()))
  t=sum(B)
  j=m
  ans=0
  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)
# Original solution
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sumA, sumB = [0], [0]
sa, sb = 0, 0
for a in A:
    sa += a
    sumA.append(sa)
for b in B:
    sb += b
    sumB.append(sb)

n_max = 0
for na in range(N+1):
    for nb in range(M+1):
        k = sumA[na] + sumB[nb]
        if k > K:
            break
        n = na + nb
        n_max = max(n_max, n)
print(n_max)


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

sumA, sumB = [0], [0]
sa, sb = 0, 0
for a in A:
    sa += a
    sumA.append(sa)
for b in B:
    sb += b
    sumB.append(sb)


n_max = 0
nb_max = M
for na in range(0, N+1):
    for nb in range(nb_max, -1, -1):
        k = sumA[na] + sumB[nb]
        if k <= K:
            n = na + nb
            n_max = max(n_max, n)
            nb_max = nb
            break
print(n_max)
# Original solution
from bisect import bisect
N, M, K = list(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]
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)

# Optimized solution
N, M, K = list(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]
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)
# Original solution
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
i = 0

for j in range(M, -1, -1):
    if ruiA[i] + ruiB[j] <= K:
        MAX = max(MAX, i+j)
        best = j
        break
    

for i in range(1, N+1):
    for j in range(best, -1, -1):
        if ruiA[i] + ruiB[j] <= K:
            MAX = max(MAX, i+j)
            break


print(MAX)


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

ruiA = [0]
ruiB = [0]
for i in range(N):
    ruiA.append(ruiA[-1] + A[i])
for i in range(M):
    ruiB.append(ruiB[-1] + B[i])

MAX = 0
j = M

for i in range(N+1):
    if ruiA[i] > K:
        break
    while ruiA[i] + ruiB[j] > K:
        j -= 1
    MAX = max(MAX, i+j)

print(MAX)
# Original solution
N,M,K = list(map(int,input().split()))
a = list(map(int,input().split()))	
b = list(map(int,input().split()))
A = [0]
B = [0]
A.extend(a)
B.extend(b)
time = sum(A)
ai = len(A)-1
bi = 0
con = 0
flg = None
count = 0
if len(a) == 1 or len(b)==1:
    time = 0
    while True:
        if len(a) == 0 and len(b)==0:
            break
        elif len(a) == 0:
            time += b[0]
            b.pop(0)
        elif len(b) == 0:
            time += a[0]
            a.pop(0)
        elif a[0] > b[0]:
            time += b[0]
            b.pop(0)
        else:
            time += a[0]
            a.pop(0)   
        if time >K:
            break
        count += 1
    print(count)
else:
    while True:
        #print("---------")
        #print(str(ai)+":"+str(bi))
        if time > K:
            if flg is not None:
                con = max(con,flg-1)
                flg = None
            
            if ai == 0:
                break
            time -=A[ai]
            ai -= 1
        else:
            #print("b")
            flg = ai+bi
            time +=B[bi]
            bi += 1
            if bi == len(B):
                if time > K:
                    pass
                else:
                    con = max(con,ai+bi-1)
                break
        #print(flg)
    print(con)

# Optimized solution
N,M,K = list(map(int,input().split()))
a = list(map(int,input().split()))	
b = list(map(int,input().split()))

A = [0]
B = [0]
A.extend(a)
B.extend(b)
time = sum(A)
ai = len(A)-1
bi = 0
con = 0
flg = None
count = 0

    

while True:
    #print("---------")
    #print(str(ai)+":"+str(bi))
    if time > K:
        if flg is not None:
            con = max(con,flg-1)
            flg = None
        
        if ai == 0:
            break
        time -=A[ai]
        ai -= 1
    else:
        #print("b")
        flg = ai+bi
        time +=B[bi]
        bi += 1
        if bi == len(B):
            if time > K:
                if flg is not None:
                    con = max(con, flg-1)
                pass
            else:
                con = max(con,ai+bi-1)
            break
    #print(flg)
print(con)
# Original solution
import sys

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

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    can_update = 1
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            if can_update == 1:
                imax_b = j
                can_update = 0

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)
                break

print(nmax)

# Optimized solution
import sys

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

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            imax_b = j

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)

            break

print(nmax)
# Original solution
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=0
book=0
for i in range(n+1):
  if a[i]>k:
    break
  for j in range(m+1):
    if a[i]+b[j]<=k:
      book=i+j
      if book>ans:
        ans = book
    else:
      break
print(ans)

# Optimized solution
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=0
for i in range(n+1):
  if a[i]>k:
    break
  for j in range(m,-1,-1):
    if a[i]+b[j]<=k:
      ans=max(ans,i+j)
      m=j
      break
print(ans)
# Original solution
import sys
import itertools as it
input = sys.stdin.readline

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

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b <= K and max < i + j:
            max = i + j
        j += 1

print(max)

# Optimized solution
import sys
import itertools as it
input = sys.stdin.readline

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

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    if max - i > 0:
        j = max - i
    else:
        j = 0
    while j < M + 1:
        b = BS[j]
        if a + b > K:
            break
        if max < i + j:
            max = i + j
        j += 1

print(max)
# Original solution
import sys
import itertools as it
input = sys.stdin.readline

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

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
for i in range(N+1):
    a = AS[i]
    if a > K:
        continue
    j = M
    while j < M + 1:
        b = BS[j]
        if a + b <= K:
            if max < i + j:
                max = i + j
            break
        j -= 1

print(max)

# Optimized solution
import sys
import itertools as it
input = sys.stdin.readline

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

AS = list(it.accumulate(A))
BS = list(it.accumulate(B))
AS.insert(0,0)
BS.insert(0,0)
max = 0
j = M
for i in range(N+1):
    if AS[i] > K:
        break
    while j >= 0:
        if AS[i] + BS[j] <= K:
            if max < i + j:
                max = i + j
            break
        j -= 1

print(max)
# Original solution
N, M, K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = []
Bsum = []
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 = 0
for i in range(-1,N):
    if Asum[i] > K:
        break
    for j in range(-1,M):
        if Asum[i] + Bsum[j] > K:
           break
        else:
           res = max(res,(i+j+2))
print(res)

# Optimized solution
N, M, K = list(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)
# Original solution
n,m,k = list(map(int, input().split()))
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))

a_li = [0] + a_li
b_li = [0] + b_li

time = 0
ans = 0
a = 0
temp = 0

a_wa = [0] * (n+10)
b_wa = [0] * (m+10)

s = 0
for i in range(n+1):
    s += a_li[i]
    a_wa[i] = s

s = 0
for i in range(m+1):
    s += b_li[i]
    b_wa[i] = s
    

for i in range(n+1):
    for j in range(m+1):
        time = a_wa[i] + b_wa[j]
        if time <= k:
            ans = max(ans, i+j)
        else:
            break
            
print(ans)

# Optimized solution
n,m,k = list(map(int, input().split()))
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))

a_li = [0] + a_li
b_li = [0] + b_li

time = 0
ans = 0
a = 0
temp = 0

a_wa = [0] * (n+10)
b_wa = [0] * (m+10)

s = 0
for i in range(n+1):
    s += a_li[i]
    a_wa[i] = s

s = 0
for i in range(m+1):
    s += b_li[i]
    b_wa[i] = s
    

for i in range(n+1):
    for j in range(max(min(temp-i, m), 0), m+1):
        time = a_wa[i] + b_wa[j]
        if time <= k:
            ans = max(ans, i+j)
            temp = ans
        else:
            break
            
print(ans)
# Original solution
from itertools import accumulate
from bisect import bisect_left

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

a = list(accumulate(A))
b = list(accumulate(B))

result = 0
j = bisect_left(b, K)
if j == M:
  result = M
elif b[j] == K:
    result = j + 1
else:
    result = j
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M:
        result = max(result, i + 1 + M)
    elif b[j] == t:
        result = max(result, i + 1 + j + 1)
    else:
        result = max(result, i + 1 + j)
print(result)


# Optimized solution
from itertools import accumulate
from bisect import bisect_left

N, M, K = list(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))

result = 0
for i in range(N + 1):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M + 1:
        result = max(result, i + M)
    elif b[j] == t:
        result = max(result, i + j)
    else:
        result = max(result, i + j - 1)
print(result)
# Original solution
from itertools import accumulate
from bisect import bisect_left

N, M, K = list(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))

result = 0
for i in range(N + 1):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M + 1:
        result = max(result, i + M)
    elif b[j] == t:
        result = max(result, i + j)
    else:
        result = max(result, i + j - 1)
print(result)


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

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
else:
    j = M - 1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)
# Original solution
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
else:
    j = M - 1
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)


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

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

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)
# Original solution
from itertools import accumulate
import bisect
n,m,k=list(map(int,input().split()))
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))

ans = max(bisect.bisect_right(B,k),bisect.bisect_right(A,k))

for i in range(len(a)):
    r = (k-A[i])
    if r<0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(B,r))
    #print(i+1,r,i+1+bisect.bisect_right(B,r))
    
for i in range(len(b)):
    r = (k-B[i])
    if r<0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(A,r))
    #print(i+1,r,i+1+bisect.bisect_right(A,r))
    
print(ans)

# Optimized solution
from itertools import accumulate
import bisect
n,m,k=list(map(int,input().split()))
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

A=list(accumulate(a))
B=list(accumulate(b))
ans=bisect.bisect_right(B,k)
for i in range(len(a)):
    r = (k-A[i])
    if r<0:
        break
    #print(r,bisect.bisect_left(B,r))
    #print(B[bisect.bisect_left(B,r)])
    ans=max(ans,i+1+bisect.bisect_right(B,r))
print(ans)