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

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

print(ans)

# Optimized solution
n, m, k = list(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)
# Original solution
import itertools

n, m, k = list(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
for i in range(n+1):
    if A[i] > k:
        break
    
    j = m
    while A[i]+B[j] > k:
        j -= 1
        
    count = max(count, i+j)
    
print(count)


# Optimized solution
import itertools

n, m, k = list(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)
# Original solution
# import io
# import sys

# _INPUT = """\
# 1 4 120
# 100 1 1 1 1 1 1 1 1 1 1
# 80 10 10 10 10
# """
# sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

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


# 累積和
from itertools import accumulate
C = list(accumulate(A))
D = list(accumulate(B))

p(*C)
p(*D)

ans = 0

for i, c in enumerate(C):
  for j, d in enumerate(D):
    p(i,j,c,d)
    if c + d > K: break
    ans = max(ans, i+j)

print(ans)


# Optimized solution
# import io
# import sys

# _INPUT = """\
# 1 4 120
# 100 1 1 1 1 1 1 1 1 1 1
# 80 10 10 10 10
# """
# sys.stdin = io.StringIO(_INPUT)

####################################################################
import sys
def p(*_a):
  return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################

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


# 累積和
from itertools import accumulate
C = list(accumulate(A))
D = list(accumulate(B))

p(*C)
p(*D)

ans = 0
d = len(D) - 1
for c in range(len(C)):
  if C[c] > K: break
  while True:
    if C[c] + D[d] <= K: break
    d -= 1

  ans = max(ans , c + d)

print(ans)
# Original solution
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

total = 0

stack = [(0, 0, 0, 0, 0)]
res = 0
flg = 0
while stack:
    av, ai, bv, bi, ans = stack.pop()
    if av + bv > K:
        res = max(res, ans-1)
        flg = 1
        continue
    if ai <= len(A) - 1:
        stack.append((av+A[ai], ai+1, bv, bi, ans+1))
        # print((av+A[ai], ai+1, bv, bi, ans+1))
    if bi <= len(B) - 1:
        stack.append((av, ai, bv+B[bi], bi+1, ans+1))
        # print((av+A[ai], ai+1, bv, bi, ans+1))

if flg:
    print(res)
else:
    print(ans)    


# Optimized solution
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

a = [0] + A
b = [0] + B

for i in range(len(a)-1):
    a[i+1] += a[i]

for i in range(len(b)-1):
    b[i+1] += 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()))
A = [0] + A
B = [0] + B
for i in range(1, N+1):
  A[i] += A[i-1]
for i in range(1, M+1):
  B[i] += B[i-1]
start = 0
end = N+1
while end-start > 1:
  sep = (start+end)//2
  if A[sep] <= K:
    start = sep
  else:
    end = sep
if start==N:
  alim = start
elif A[end]>K:
  alim = start
else:
  alim = end
blim = 0
start = blim
end = M+1
ans = alim
ansalim = -1
ansblim = -1
for _ in range(alim+1):
  Bmax = K-A[alim]
  #print("Bmax" , Bmax)
  while end-start > 1:
    sep = (start+end)//2
    #print(blim,start, end, sep)
    if B[sep] <= Bmax:
      start = sep
    else:
      end = sep
  if start==M:
    blim = start
  elif B[end]>Bmax:
    blim = start
  else:
    blim = end
  
  ans = max(blim + alim, ans)
  start = sep-1
  end = M+1
  alim -= 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_wa = [0]
for i in range(N) :
    A_wa.append(A_wa[i]+A[i])

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

a = N
ans = 0
for b in range(M+1):
  A_lim = K - B_wa[b]
  if A_lim < 0:
    break
  while A_wa[a] > A_lim and a > 0:
    a -= 1
  ans = max(a + b, ans)
print(ans)
# Original solution
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
s = 0
b_count = 0
for i in range(m):
    if s + b[i] <= k:
        s += b[i]
        ans += 1
        b_count = i+1
    else:
        break
a_count = 0
while True:
    if a_count < n and s+a[a_count] <= k:
        s += a[a_count]
        a_count += 1
        ans += 1
    else:
        break
now = ans
for i in range(b_count-1, -1, -1):
    s -= b[i]
    now -= 1
    while True:
        if a_count < n and s +a[a_count] <= k:
            s += a[a_count]
            a_count += 1
            now += 1
        else:
            break
    ans = max(now, ans)
print(ans)

# Optimized solution
n, m, k = list(map(int,input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0]
for i in range(n):
    sa.append(sa[-1] + a[i])
inf = 1001001001
sb = [-inf, 0]
for i in range(m):
    sb.append(sb[-1] + b[i])
sb.append(inf)
ans = 0
for i in range(n+1):
    s = sa[i]
    l = 0
    r = len(sb) - 1
    while l+1 < r:
        m = (l+r) //2
        if s + sb[m] <= k:
            l = m
        else:
            r = m
    if l == 0:
        continue
    else:
        ans = max(ans, i+l-1)
print(ans)
# Original solution
n,m,k=list(map(int,input().split()))
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
for i in range(n): #累積和ai,bjを求める
 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: #ai>Kであれば、どのようにjを選んでもai+bj<=Kとなることはないので探索を終了する
   break
 while acum2[j]>k-acum1[i] and j>0: #各iについて、bj<=K-aiを満たす最大のjを求める
   j-=1
 ans=max(ans,i+j)
print(ans)

# Optimized solution
n,m,k=list(map(int,input().split()))
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
acum1=[0]
#累積和ai,bjを求める
for i in range(n): 
	# acum[-1]で一番最後のリストの値を参照している
    # うしろからみている
 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):
    #各iについて、bj<=K-aiを満たす最大のjを求める
    #bj>K-aiの間、ループ。jを大きい方から順に調べていく
    #限界ギリギリを調べるのだから、後ろから調べた方がよいという感じかな
 if acum1[i]>k:
   break
       #各iについて、bj<=K-aiを満たす最大のjを求める
    #bj>K-aiの間、ループ。jを大きい方から順に調べていく
    #限界ギリギリを調べるのだから、後ろから調べた方がよいという感じかな
 while acum2[j]>k-acum1[i] and j>0: 
   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()))
ans = 0

a.insert(0, 0)
b.insert(0, 0)

for i in range(n+1):
    if sum(a[0:i+1]) > k:
        break
    for j in range(m+1):
        if sum(a[0:i+1]) + sum(b[0:j+1]) > k:
            break
        if sum(a[0:i+1]) + sum(b[0:j+1]) <= k and i + j > ans:
            ans = i + j

print(ans)

# Optimized solution
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
amax = 0
samax = 0

for i in range(n):
    if samax + a[i]<=k:
        amax += 1
        samax += a[i]
    else:
        break
        
book = amax
ans = book
samax = sum(a[0:amax])
sbmax = 0

for j in range(m):
    sbmax += b[j]
    while samax + sbmax > k and amax >= 1:
        amax -= 1
        samax = samax - a[amax]
        book -= 1
    if samax + sbmax <= k:
        book += 1
        if book > ans:
            ans = book
    else:
        break

print(ans)
# Original solution
import itertools
n, m, k = list(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):
    for j in range(m + 1):
        if (sa[i] + sb[j] <= k):
            if i + j > max:
                max = i + j 
        else:
            break
print(max)

# Optimized solution
import itertools
n, m, k = list(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))

output = 0
j = m
for i in range(n + 1):
    if sa[i] > k:
        break
    while sa[i] + sb[j] > k:
        j -= 1
    if output < i + j:
        output = i + j
print(output)
# Original solution
from itertools import accumulate
N, M, K = list(map(int,input().split()))
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))

for n in range(N + 1):
    if A_sums_list[n] > K:
        break
    A_max = n
for m in range(M + 1):
    if B_sums_list[m] > K:
        break
    B_max = m
ans = max(A_max, B_max)

for i in reversed(list(range(A_max + 1))):
    for j in reversed(list(range(B_max + 1))):
        if i + j > ans:
            if A_sums_list[i] + B_sums_list[j] <= K:
                ans = i + j
                break
        else:
            break
print(ans)

# Optimized solution
from itertools import accumulate
N, M, K = list(map(int,input().split()))
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))
ans = 0
for i, A_sums in enumerate(A_sums_list):
    B_min = 0
    B_max = M + 1
    while True:
        B_index = int((B_max + B_min) * 0.5)
        if A_sums + B_sums_list[B_index] <= K:
            B_min = B_index
        else:
            B_max = B_index
        if B_max - B_min == 1:
            break   
    if i + B_min > ans and A_sums + B_sums_list[B_min] <= K:
        ans = i + B_min
print(ans)
# Original solution
from itertools import accumulate
N, M, K = list(map(int,input().split()))
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))
ans = 0
for i, A_sums in enumerate(A_sums_list):
    B_min = -1
    B_max = M + 1
    while B_max - B_min > 1:
        B_index = int((B_max + B_min) * 0.5)
        if A_sums + B_sums_list[B_index] <= K:
            B_min = B_index
        else:
            B_max = B_index
    B_index = int((B_max + B_min) * 0.5)
    if i + B_index > ans and A_sums + B_sums_list[B_index] <= K:
        ans = i + B_index
print(ans)

# Optimized solution
from itertools import accumulate
N, M, K = list(map(int,input().split()))
A_list = [0] + list(map(int,input().split()))
B_list = [0] + list(map(int,input().split()))
A_sums_list = list(accumulate(A_list))
B_sums_list = list(accumulate(B_list))
ans = 0
for i, A_sums in enumerate(A_sums_list):
    B_min = -1
    B_max = M + 1
    while B_max - B_min > 1:
        B_index = int((B_max + B_min) * 0.5)
        if A_sums + B_sums_list[B_index] <= K:
            B_min = B_index
        else:
            B_max = B_index
#    B_index = int((B_max + B_min) * 0.5)
    if i + B_min > ans and A_sums + B_sums_list[B_min] <= K:
        ans = i + B_min
print(ans)
# Original solution
from collections import deque
from sys import exit

N, M, K = [int(x) for x in input().split()]

a_book = [0]
for index, i in enumerate(input().split(), 1):
    if a_book[index-1] + int(i) <= K:
        a_book.append(a_book[index-1] + int(i))
    else:
        N = index - 1
        break

b_book = [0]
for index, i in enumerate(input().split(), 1):
    if b_book[index-1] + int(i) <= K:
        b_book.append(b_book[index-1] + int(i))
    else:
        M = index - 1
        break

search = deque()
check = {}

max_books = 0

for a_pos in range(N, -1, -1):
    a = a_book[a_pos]
    b_pos = 0
    for x in range(b_pos, M+1):
        if a + b_book[x] > K:
            break

        if max_books < a_pos + x:
            max_books = a_pos + x

print(max_books)


# Optimized solution
from bisect import bisect_right
from time import time

N, M, K = [int(x) for x in input().split()]

a_book = [0]
for index, i in enumerate(input().split(), 1):
    if a_book[index-1] + int(i) <= K:
        a_book.append(a_book[index-1] + int(i))
    else:
        N = index - 1
        break

b_book = [0]
for index, i in enumerate(input().split(), 1):
    if b_book[index-1] + int(i) <= K:
        b_book.append(b_book[index-1] + int(i))
    else:
        M = index - 1
        break

check = {}

max_books = 0

for i, a in enumerate(a_book):
    b_pos = bisect_right(b_book, K - a)

    if max_books < b_pos - 1 + i:
        max_books = b_pos - 1 + i

print(max_books)
# Original solution
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

tmp = []
s = 0
for i in a:
    if s + i <= k:
        tmp.append(i)
        s += i
a = tmp
tmp = []
s = 0
for i in b:
    if s + i <= k:
        tmp.append(i)
        s += i
b = tmp
line = b[::-1] + a

ans = 0
left = 0
for left in range(len(line)):
    sum_ = 0
    right = left
    while right < len(line) and sum_ + line[right] <= k:
        sum_ += line[right]
        right += 1
    l = right -left
    if l > ans:
        ans = l
print(ans) 

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

tmp = []
s = 0
for i in a:
    if s + i <= k:
        tmp.append(i)
        s += i
    else:
        break
a = tmp
tmp = []
s = 0
for i in b:
    if s + i <= k:
        tmp.append(i)
        s += i
    else:
        break
b = tmp
line = b[::-1] + a

ans = 0
right = 0
sum_ = 0
for left in range(len(line)):
    while right < len(line) and sum_ + line[right] <= k:
        sum_ += line[right]
        right += 1
    l = right -left 
    if l > ans:
        ans = l

    if right == left: right += 1
    else: sum_ -= line[left]

print(ans)
# Original solution
from itertools import accumulate
from bisect import bisect_right

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

acc_a = list(accumulate(a))
acc_b = list(accumulate(b))

ans = 0
for i, e in enumerate(acc_b):
    if e > k:
        break
    a_cnt = bisect_right(acc_a, k - e)
    ans = max(ans, i + a_cnt)

print(ans)


# Optimized solution
from itertools import accumulate

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
INF = 10 ** 18

acc_a = [0] + list(accumulate(a))
acc_b = [0] + list(accumulate(b))
j = m
ans = 0
for i, e in enumerate(acc_a):
    while j >= 0 and acc_b[j] > k - acc_a[i]:
        j -= 1

    if j == -1:
        break

    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()))
A_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])    
import bisect
ans = 0
for i in range(N+1):
    a = A_sum[i]
    if K-a >=0:
        b_idx = bisect.bisect(B_sum, K-a) - 1
        if b_idx  < 0:
            b_idx = 0
        ans = max(ans, i+b_idx)
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_sum = [0]
for i in range(N):
    A_sum.append(A[i] + A_sum[i])
B_sum = [0]
for i in range(M):
    B_sum.append(B[i] + B_sum[i])   
    
b_idx = 0
for i in range(1, M+1):
    if B_sum[i] <= K:
        b_idx = i
ans = 0
for i in range(N+1):
    if b_idx > 0:
        while A_sum[i] + B_sum[b_idx] > K:
            b_idx -= 1
            if b_idx < 0:
                b_idx = 0
                break
    if A_sum[i] + B_sum[b_idx] <= K:
        ans = max(ans, i+b_idx)
print(ans)
# Original solution
n, m, k = list(map(int, input().split()))
alst = list(map(int, input().split()))
blst = list(map(int, input().split()))

amax = 0
count = 0

for i in alst:
    if alst[amax] + count <= k:
        count += alst[amax]
        amax += 1
    else:
        break
# print("a:" + str(amax))
"""
while alst[amax] + count <= k:
    # print(str(amax) + " " + str(count))
    count += alst[amax]
    amax += 1
# print(amax)
#amaxはaの最大冊数
"""

anslst = []
count = 0
for i in range(amax+1):
    count = sum(alst[:i])
    bmax = 0
    for j in blst:
        if blst[bmax] + count <= k:
            count += blst[bmax]
            bmax += 1
        else:
            break
    # print("i:" + str(i) + " b:" + str(bmax))
    anslst.append(i+bmax)

print((max(anslst)))


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

asum = [0]
bsum = [0]

for i, new in enumerate(alst):
    if asum[i] + new <= k:
        asum.append(asum[i] + new)
    else:
        break
for i, new in enumerate(blst):
    if bsum[i] + new <= k:
        bsum.append(bsum[i] + new)
    else:
        break

bmax = len(bsum)-1
ans = 0

for i, atime in enumerate(asum):
    while atime + bsum[bmax] > k:
        bmax -= 1
    ans = max(ans, i+bmax)

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

if sum(A) <= K:
    a_max = N
    ans = N

else:
    a_total = 0
    for i in range(N):
        a_total += A[i]
        if a_total > K:
            break
    a_max = i
    ans = a_max


for i in range(a_max+1)[::-1]:
    total = sum(A[:i])
    #print('b total: ', total)
    if total + sum(B) <= K:
        ans = max(ans, i + M)
    else:
        for j in range(M):
            total += B[j]
            #print('a total: ', total)
            if total > K:
                flag = True
                break
        ans = max(ans, i + j)
    #print('ans: ', ans)
    #print()

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]*N, [0]*M

total = 0
for i in range(N):
    total += A[i]
    a[i] = total

a = [0] + a

total = 0
for i in range(M):
    total += B[i]
    b[i] = total

b = [0] + b

ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] + a[i] > K:
        j -= 1
    #print(a[i], b[j], i, j)
    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()))
from itertools import accumulate
ar=[0]+list(accumulate(a))
bru=[0]+list(accumulate(b))
from bisect import bisect_left as bl,bisect_right as br
ans=0
nb=0
for i in range(n,-1,-1):
    if ar[i]>k:continue
    while nb<m and ar[i]+bru[nb]<k:
        nb+=1
    if ar[i]+bru[nb]>k:nb-=1
    ans=max(ans,i+nb)

print(ans)

# Optimized solution
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from itertools import accumulate
ar=[0]+list(accumulate(a))
bru=[0]+list(accumulate(b))
from bisect import bisect_left as bl,bisect_right as br
ans=0

for i in range(n+1):
    g=ar[i]
    if g>k:break
    if k-g>=bru[-1]:ans=max(ans,i+m);continue
    j=br(bru,k-g)
    ans=max(ans,i+j-1)
    #print(i,j-1)
print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**6)


def DFS(point,left,right,cnt):
    global ans
    if point<=k:
        if cnt>ans:
            ans=cnt

    if left<n:
        if point+A[left]<=k:DFS(point+A[left],left+1,right,cnt+1)
    if right<m:
        if point+B[right]<=k:DFS(point+B[right],left,right+1,cnt+1)


n,m,k=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
DFS(0,0,0,0)
print(ans)

# Optimized solution
n,m,k=list(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]+A[i]
for i in range(1,m+1):
    B[i]=B[i-1]+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()))
sum_A=0
sum_B=0
for i in range(N):
    sum_A +=A[i]
    if sum_A>K:
        del A[i:]
        break
for i in range(M):
    sum_B +=B[i]
    if sum_B>K:
        del B[i:]
        break
while sum(A)+sum(B)>K:
    if A[-1]>B[-1]:
        del A[-1]
    elif A[-1]<B[-1]:
        del B[-1]
    elif A[-1] == B[-1]:
        del A[-1]
        del B[-1]
        if sum(A)+sum(B)<=K:
            A.append(1)
print((len(A)+len(B)))

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

# Optimized solution
n,m,k=list(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 k<a[i]:
        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()))
A=[0]
B=[0]


for i in range(1,len(a)+1):
    A.append(a[i-1]+A[i-1])

for i in range(1,len(b)+1):
    B.append(b[i-1]+B[i-1])
    

maxman=0
for i in range(len(A)):
    for j in range(len(B)):
        if A[i]+B[j]<=k:
            maxman=max(maxman,i+j)
            
print(maxman)

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