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

suma = [0 for i in range(len(a)+1)]
sumb = [0 for i in range(len(b)+1)]

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

for i in range(1, len(b)+1):
    sumb[i] = sumb[i-1] + b[i-1]

mnum = 0
for i in range(len(suma)):
    num = 0
    for j in range(len(sumb))[::-1]:
        if suma[i] + sumb[j] <= k:
            num = i + j
            break
    if num > mnum:
        mnum = num

print(mnum)

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

suma = [0 for i in range(len(a)+1)]
sumb = [0 for i in range(len(b)+1)]

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

for i in range(1, len(b)+1):
    sumb[i] = sumb[i-1] + b[i-1]

mnum = 0
best = len(sumb)
for i in range(len(suma)):
    for j in range(best)[::-1]:
        if suma[i] + sumb[j] <= k:
            mnum = max(mnum, i+j)
            best = j+1
            break

print(mnum)
# 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]
p = 0
q = 0
for i in range(N):
  if p + A[i] > K:
    break
  a.append(p+A[i])
  p += A[i]
for i in range(M):
  if q + B[i] > K:
    break
  b.append(q+B[i])
  q += B[i]
ans = 0
for n, s in enumerate(a):
  if s > K:
    break
  for m, t in enumerate(b):
    if s + t <= K:
      ans = max(ans, n+m)
    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 = [0]
b = [0]
p = 0
for i in range(N):
  p += A[i]
  a.append(p)
q = 0
for j in range(M):
  q += B[j]
  b.append(q)
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)
# 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]
b_sum = [0]
for i in range(n):
    a_sum.append(a[i]+a_sum[i])
    if a_sum[i]>k:
        break
for i in range(m):
    b_sum.append(b[i]+b_sum[i])
    if b_sum[i]>k:
        break
        
ans = 0
for i in range(len(a_sum)):
    if a_sum[i]>k:
        break
    time = k - a_sum[i]
    for j in range(len(b_sum)-1,-1,-1):
        if time>=b_sum[j]:
            break
    if time>=b_sum[len(b_sum)-1]:
        j = len(b_sum)-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()))
a_sum = [0]
b_sum = [0]
for i in range(n):
    a_sum.append(a[i]+a_sum[i])
    if a_sum[i]>k:
        break
for i in range(m):
    b_sum.append(b[i]+b_sum[i])
    if b_sum[i]>k:
        break
        
ans = 0
y = len(b_sum)-1
for i in range(len(a_sum)):
    if a_sum[i]>k:
        break
    time = k - a_sum[i]
    for j in range(y,-1,-1):
        if time>=b_sum[j]:
            y = j
            break
    if time>=b_sum[len(b_sum)-1]:
        j = len(b_sum)-1
    ans = max(ans,i+j)
    
print(ans)
# Original solution
from sys import stdin
import bisect

sysin=stdin.readline

N,M,K=[int(x) for x in sysin().rstrip().split()]
a=[int(x) for x in sysin().rstrip().split()]
b=[int(x) for x in sysin().rstrip().split()]

# N,M=3,4
# K=240
# a=[60, 90, 120]
# b=[80, 150, 80, 150]

ans=0

accum_a=[0]
for i in a:
    _a=accum_a[-1]+i
    if _a>K:
        break
    else:
        accum_a.append(_a)
accum_a.append(K)

accum_b=[0]
for i in b:
    accum_b.append(accum_b[-1]+i)

ans=0

for j in range (len(accum_a)-1):
    Kb=K-accum_a[j]
    bookB=bisect.bisect_right(accum_b,Kb)-1
    if j+bookB>ans:
        ans=j+bookB
    else:
        pass

print(ans)

# Optimized solution
import bisect

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


totaltame_a=[0]
for a in list_a:
    temp_a=totaltame_a[-1]+a
    if temp_a>K:
        break
    else:
        totaltame_a.append(temp_a)


totaltime_b=[0]
for b in list_b:
    totaltime_b.append(totaltime_b[-1]+b)

ans=0

for i in range (len(totaltame_a)):
    Kb=K-totaltame_a[i]
    j=bisect.bisect_right(totaltime_b,Kb)-1
    if i+j>ans:
        ans=i+j
    else:
        pass

print(ans)
# Original solution
from bisect import bisect_right as br
n,m,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
sa = [0]*(n+1)
for i in range(n): sa[i+1] = sa[i]+a[i]
b = [int(i) for i in input().split()]
sb = [0]*(m+1)
for i in range(m): sb[i+1] = sb[i]+b[i]
ans = 0
for i in range(n+1):
    cnt = sa[i]
    if cnt > k: break
    ans = max(ans,br(sb,k-cnt)-1+i)
print(ans)

# Optimized solution
from bisect import bisect_right as br
n,m,k = list(map(int,input().split()))
a = [int(i) for i in input().split()]
sa = [0]*(n+1)
for i in range(n): sa[i+1] = sa[i]+a[i]
b = [int(i) for i in input().split()]
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
    ans = max(ans,br(sb,k-sa[i])-1+i)
print(ans)
# Original solution
from bisect import *
def solve():
    ans = 0
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))+[float('inf')]
    B = list(map(int, input().split()))+[float('inf')]
    cumA = [0]*(N+1)
    cumB = [0]*(M+1)
    for i in range(N):
        cumA[i+1] = cumA[i]+A[i]
    for i in range(M):
        cumB[i+1] = cumB[i]+B[i]
    for i in range(N+1):
        rest = K-cumA[i]
        if rest<0:
            break
        ind = bisect_right(cumB,rest)
        ans = max(ans,i+ind-1)
    return ans
print((solve()))

# Optimized solution
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
    ans = 0
    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))
    b = M
    for a in range(N+1):
        if A[a]>K:
            break
        while A[a]+B[b]>K:
            b -= 1
        ans = max(a+b,ans)
    return ans
print((solve()))
# Original solution
N, M, K = list(map(int, input().split()))

time_A = list(map(int, input().split()))
time_B = list(map(int, input().split()))
max_books = 0
allot_to_A = 0
allot_to_B = K

while True:
    if max_books == len(time_A) + len(time_B):
        break
    num_books = 0
    change_point = 10000000000
    time_bankA = allot_to_A
    time_bankB = allot_to_B

    for i in range(len(time_A)):
        if time_A[i] <= time_bankA:
            time_bankA -= time_A[i]
            num_books += 1
        else:
            change_point = time_A[i] - time_bankA  # Aで読める本が１冊増える時間
            break

    for j in range(len(time_B)):
        if time_B[j] <= time_bankB:
            time_bankB -= time_B[j]
            num_books += 1
        else:
            break

    max_books = max(max_books, num_books)
    allot_to_A += change_point
    allot_to_B -= change_point
    if allot_to_A < 0 or allot_to_B < 0:
        break

print(max_books)


# 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
from bisect import bisect
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i+1] = SA[i] + A[i]
for i in range(M):
    SB[i+1] = SB[i] + B[i]
result = 0
for x in range(N+1):
    if SA[x] > K:
        break
    y = bisect(SB, K - SA[x]) - 1
    result = max(result, x + y)
print(result)

# Optimized 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()))
SA = [0] * (N + 1)
SB = [0] * (M + 1)
for i in range(N):
    SA[i+1] = SA[i] + A[i]
for i in range(M):
    SB[i+1] = SB[i] + B[i]

result = 0
y = M
for x in range(N+1):
    if SA[x] > K:
        break
    while y >= 0 and SA[x] + SB[y] > K:
        y -= 1
    result = max(result, x + y)
print(result)
# 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] * (n + 1)
b_sum = [0] * (m + 1)
for i in range(n):
    a_sum[i + 1] = a_sum[i] + a[i]
for i in range(m):
    b_sum[i + 1] = b_sum[i] + b[i]
res = 0
for i in range(n+1):
    for j in range(m+1):
        if a_sum[i] + b_sum[j] <= k:
            res = max(res, i + j)
        else:
            break
print(res)

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

a_num = 0
b_num = 0
book_num = 0
passed_k = 0
for i in range(n):
    if a[i] + passed_k <= k:
        a_num += 1
        passed_k += a[i]
    else:
        break
for i in range(m):
    if b[i] + passed_k <= k:
        b_num += 1
        passed_k += b[i]
    else:
        break
book_num = a_num + b_num

while a_num > 0:
    passed_k -= a[a_num - 1]
    a_num -= 1
    while b_num < m:
        if passed_k + b[b_num] <= k:
            passed_k += b[b_num]
            b_num += 1
        else:
            break
    book_num = max(book_num, a_num + b_num)
    if b_num == m:
        break

print(book_num)
# Original solution
import bisect

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

da = [0 for _ in range(N+1)]
for i in range(N):
    da[i+1] = da[i] + a[i]
db = [0 for _ in range(M+1)]
for i in range(M):
    db[i+1] = db[i] + b[i]

ans = 0
for i in range(N+1):
    if da[i] > K:
        break
    ans = max(ans, i + bisect.bisect_right(db, K-da[i]) - 1)
print(ans)

# Optimized solution
N, M, K = list(map(int, input().split()))
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

da = [0 for _ in range(N+1)]
for i in range(N):
    da[i+1] = da[i] + a[i]
db = [0 for _ in range(M+1)]
for i in range(M):
    db[i+1] = db[i] + b[i]

ans = 0; j = M
for i in range(N+1):
    if da[i] > K:
        break
    while db[j] > K - da[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(N):
    a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i] +B[i])
ans = 0
best = M
for i in range(N+1):
    if a[i] > K:
        break
    for j in range(best, -1, -1):
        if a[i] + b[j] <= K:
            ans = max(ans, i+j)
            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 = [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)
# Original solution
import bisect
# listのpopを使う
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
# 純粋に小さい方を読んでいく
ans = 0
# 1番上しか読めない
# while K >= A[0] or K >= B[0]:
#     if A[0]
cumulative_sum_of_A = [0]
cumulative_sum_of_B = [0]
for i in range(N):
    cumulative_sum_of_A.append(cumulative_sum_of_A[-1]+A[i])

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

# print(cumulative_sum_of_A)
# print(cumulative_sum_of_B)

ans = 0
for i in range(N+1):
    # print(ans)
    if cumulative_sum_of_A[i] > K:  # それ以上Aを読めないならアウト
        break
    tmp = i  # A側の本をi冊読む  # 0の場合もあり
    remaining = K - cumulative_sum_of_A[i]  # 残り時間
    upper_bound = bisect.bisect_right(cumulative_sum_of_B, remaining)-1
    tmp += upper_bound
    ans = max(tmp, ans)
print(ans)


# Optimized solution
from bisect import bisect_left, bisect_right
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruisekiwa_of_A = [0]
ruisekiwa_of_B = [0]
for a in A:
    ruisekiwa_of_A.append(ruisekiwa_of_A[-1]+a)
for b in B:
    ruisekiwa_of_B.append(ruisekiwa_of_B[-1]+b)
# ansの最大値をとる
ans = 0
for i in range(N+1):
    tmp = 0
    if K >= ruisekiwa_of_A[i]:
        tmp = i
    else:
        continue
    tmp += bisect_right(ruisekiwa_of_B, K-ruisekiwa_of_A[i])-1
    ans = max(ans, tmp)
print(ans)
# Original solution
from bisect import bisect_left, bisect_right
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruisekiwa_of_A = [0]
ruisekiwa_of_B = [0]
for a in A:
    ruisekiwa_of_A.append(ruisekiwa_of_A[-1]+a)
for b in B:
    ruisekiwa_of_B.append(ruisekiwa_of_B[-1]+b)
# ansの最大値をとる
ans = 0
for i in range(N+1):
    tmp = 0
    if K >= ruisekiwa_of_A[i]:
        tmp = i
    else:
        continue
    tmp += bisect_right(ruisekiwa_of_B, K-ruisekiwa_of_A[i])-1
    ans = max(ans, tmp)
print(ans)


# Optimized solution
from bisect import bisect_right
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ruisekiwa_of_a = [0]
ruisekiwa_of_b = [0]
for a in A:
    ruisekiwa_of_a.append(ruisekiwa_of_a[-1]+a)
for b in B:
    ruisekiwa_of_b.append(ruisekiwa_of_b[-1]+b)
# print(ruisekiwa_of_a)
# print(ruisekiwa_of_b)
ans = 0
for i in range(N+1):
    if ruisekiwa_of_a[i] > K:
        continue
    tmp = i
    tmp += bisect_right(ruisekiwa_of_b, K-ruisekiwa_of_a[i])-1
    ans = max(ans, tmp)
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))

ans = 0
pt = len(B)-1
for i,sa in enumerate(SA):
    while(pt>=0):
        if sa + SB[pt] <= K:
            ans = max(ans,i+pt)
            break
        pt-=1
print (ans)





# 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))
ans = 0
j = len(B)-1
for i in range(len(SA)):
    while(j>=0):
        if SA[i] + SB[j] <= K:
            ans = max(ans,i+j)
            break
        j-=1
print (ans)
# Original solution
n, m, k = list(map(int, input().split(' ')))
list_a = list(map(int, input().split(' ')))
list_b = list(map(int, input().split(' ')))
 
a_sum=[list_a[0]]
for i in range(1, n):
  a_sum.append(list_a[i]+a_sum[i-1])
  
b_sum=[list_b[0]]
for i in range(1, m):
  b_sum.append(list_b[i]+b_sum[i-1])

  
ans=0 
if (a_sum[0]>k) and (b_sum[0]>k):
  print((0))
else:
  for j in range(m):
    if b_sum[j]<=k:
      ans=max(ans, j+1)
  j=m-1
  for i in range(n):
    if a_sum[i]<=k:
      ans=max(ans, i+1)
      while a_sum[i] + b_sum[j] > k and j>0:
        j-=1
      if a_sum[i]+b_sum[j]<=k:
        ans=max(ans, i+j+2)
  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])
  
ans, j = 0, m
for i in range(n+1):
  if a_sum[i]>k:
    break
  while a_sum[i] + b_sum[j] > k and j>0:
    j-=1
  if a_sum[i]+b_sum[j]<=k:
    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()))

n = N
while True:
    if sum(A[:n]) <= K:
        break
    n -= 1

m = M
max_num = 0
for n in range(n + 1):
    #print(n, m)
    if sum(A[:n]) > K:
        break
    while True:
        #print(n, m)
        if sum(A[:n]) + sum(B[:m]) <= K:
            max_num = max(max_num, n+m)
            break
        m -= 1
# print(cost)
print(max_num)


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

ma = [0] * (N + 1)
mb = [0]*(M+1)


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

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

j = M
max_num = 0

for i in range(N+1):
    if ma[i] > K:
        break
    while ma[i] + mb[j] > K:
        j -= 1
    max_num = max(max_num, i + j)
print(max_num)
# Original solution
n, m, k = list(map(int, input().split()))

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

Acum = [0]*n
Bcum = [0]*m
Acum[0] = A[0]
Bcum[0] = B[0]

for i in range(1,n):
  Acum[i] = Acum[i-1] + A[i]  
for i in range(1,m):
  Bcum[i] = Bcum[i-1] + B[i]

mx = 0
for i in range(n+1):
  cnt = 0
  if i==0:
    rest = k
  else:
    rest = k - Acum[i-1]
    cnt = i
    if rest<0:continue
  
  for j in range(m):
    if rest<Bcum[j]:
      cnt += j
      break
  if rest>=Bcum[-1]:
    cnt += m
  if cnt>mx:
    mx = cnt
    
print(mx)

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

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

Acum = [0]*n
Bcum = [0]*m
Acum[0] = A[0]
Bcum[0] = B[0]

for i in range(1,n):
  Acum[i] = Acum[i-1] + A[i]  
for i in range(1,m):
  Bcum[i] = Bcum[i-1] + B[i]

mx = 0

import bisect
for i in range(n+1):
  cnt = 0
  if i==0:
    rest = k
  else:
    rest = k - Acum[i-1]
    cnt = i
    if rest<0:continue
  
  idx = bisect.bisect_right(Bcum, rest)
  cnt += idx

  if cnt>mx:
    mx = cnt
    
print(mx)
#print(bisect.bisect_right([0,1], 0))
# Original solution
from sys import exit
import copy
# import numpy as np
from collections import deque

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

cnt = 0


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]


for i in range(n+1):
    for j in range(m+1):
        if a[i] + b[j] <= k:
            pass
        else:
            if a[i] + b[j-1] <= k:
                cnt = max(cnt, i + j - 1)
            break
    else:
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
print(cnt)


# Optimized solution
from sys import exit
import copy
# import numpy as np
from collections import deque

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

cnt = 0


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]

tmp = m
for i in range(n+1):
    for j in range(tmp, -1, -1):
        if a[i] + b[j] <= k:
            cnt = max(cnt, i + j)
            tmp = j
            break


print(cnt)
# Original solution
def getIntList(strList):
  return list([int(x) for x in strList])

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

ta = 0
tb = 0
TA = [0]
TB = [0]

for i in range(len(A)):
  ta += A[i]
  if ta <= K:
    TA.append(ta)
  else:
    break
for j in range(len(B)):
  tb += B[j]
  if tb <= K:
    TB.append(tb)
  else:
    break

cnt = []

for i in range(len(TA)):
  for j in range(len(TB)):
#    print(" ".join([str(TA[i]), str(TB[-j-1]), str(K)]))
    if TA[i] + TB[-j-1] <= K:
      cnt.append(i - j + len(TB) - 1)
#      print(" ".join([str(i), str(j), str(len(TB)), "-1"]))
      break

print((max(cnt)))
      

# Optimized solution
def getIntList(strList):
  return list([int(x) for x in strList])

N, M, K = getIntList(input().split(" "))
A = getIntList(input().split(" "))
B = getIntList(input().split(" "))

ta = 0
tb = 0
TA = [0]
TB = [0]

for i in range(len(A)):
  ta += A[i]
  if ta <= K:
    TA.append(ta)
  else:
    break
for j in range(len(B)):
  tb += B[j]
  if tb <= K:
    TB.append(tb)
  else:
    break

Cij = [0]

j = len(TB) - 1
for i in range(len(TA)):
  while TA[i] + TB[j] > K:
    j += -1
  else:
    if j >= 0:
      Cij.append(i + j)
  if j == -1:
    break


print((max(Cij)))
# Original solution
from itertools import *
from bisect import bisect_right
n,m,time = 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))

ans = 0
for i in range(bisect_right(A, time)-1,-1,-1):
    for j in range(bisect_right(B, time)-1,-1,-1):
        if A[i] + B[j] <= time:
            ans = max(ans,i+j)
print(ans)


# Optimized solution

from itertools import *
from bisect import bisect_right
n,m,time = 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))

ans = 0
for i in range(bisect_right(A, time)-1,-1,-1):
    ans = max(ans,i+bisect_right(B, time-A[i])-1)
print(ans)
# Original solution
from itertools import accumulate
n,m,k = list(map(int,input().split()))
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
cumA = list(accumulate(deskA))
cumB = list(accumulate(deskB))
cumA = [0] + cumA
cumB = [0] + cumB
ans = 0
l = m
for i in range(n+1):
    tmp = k - cumA[i]
    if tmp<0:
        continue
    j = l
    tmp -= cumB[j]
    while tmp < 0:
        tmp += cumB[j]
        j -= 1
        tmp -= cumB[j]
    l = j
    ans = max(i+j,ans)
print(ans)

# Optimized solution
from itertools import accumulate
n,m,k = list(map(int,input().split()))
deskA = list(map(int,input().split()))
deskB = list(map(int,input().split()))
cumA = [0] + list(accumulate(deskA))
cumB = [0] + list(accumulate(deskB))
ans = 0
j = m
for i in range(n+1):
    if cumA[i] > k:
        continue
    while cumA[i] + cumB[j] > k:
        j -= 1
    ans = max(i+j,ans)
print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

N, M, lim = mi()
A = li()
B = li()

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

for i in range(N+1):
    right = 0
    cnt = 0
    wa = 0
    left = 0

    while right < M and wa + B[right] <= lim - A[i]:
        wa += B[right]
        right += 1

    cnt = right - left

    if cnt > 0 or A[i] <= lim:
        ans = max(ans, cnt+i)

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return list(map(int, sys.stdin.readline().split()))
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
from itertools import accumulate #list(accumulate(A))

N, M, lim = mi()
A = li()
B = li()

A = [0] + list(accumulate(A))
B = [0] + list(accumulate(B))
ans = 0
'''
for i in range(N+1):
    if lim < A[i]:
        continue
    #right = 0
    cnt = 0
    wa = 0

    while right < M and wa + B[right] <= lim - A[i]:
        wa += B[right]
        right += 1

    cnt = right - left

    if cnt > 0:
        ans = max(ans, cnt+i)

print(ans)
'''
right = M

for i in range(N+1):
    if A[i] > lim:
        continue

    while True:
        if right < 0 or A[i] + B[right] <= lim:
            break
        right -= 1
    
    #print(i, right)
    ans = max(ans, i + right)
    
print(ans)