CodeEff/ECCO huggingface dataset:
# Original solution
import itertools
import bisect

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

aa = [0] + list(itertools.accumulate(A))
bb = [0] + list(itertools.accumulate(B))

ans = 0
for i in reversed(list(range(N+1))):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if i + M <= ans:
        continue

    if ans != 0 and bb[(ans-i+1)] >= tmp_K:
        continue

    if tmp_K >= bb[-1]:
        ans = max(ans, i+M)
        continue

    mn = 0
    mx = M
    while True:
        if mn == mx:
            if tmp_K >= bb[mn]:
                ans = max(ans, i+mn)
            break

        mid = (mn+mx//2)
        if bb[mid] <= tmp_K:
            if mn == mid:
                mn = mid+1
            else:
                mn = mid

        else:
            if mx == mid:
                mx = mid-1
            else:
                mx = mid
            if i+mx <= ans:
                break
print(ans)


# Optimized solution
import itertools
import bisect

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

aa = [0] + list(itertools.accumulate(A))
bb = [0] + list(itertools.accumulate(B))

ans = bisect.bisect_left(aa, K)-1
ans = max(ans, bisect.bisect_left(bb, K)-1)

for i in reversed(list(range(N+1))):
    tmp_K = K-aa[i]
    if tmp_K == 0:
        ans = max(ans, i)
    elif tmp_K < 0:
        continue

    if i + M <= ans:
        continue

    if tmp_K >= bb[-1]:
        ans = max(ans, i+M)
        continue

    ans = max(ans, bisect.bisect_left(bb, tmp_K)-1+i)
print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**9)

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

ans = 0


def shouka(s: str, pa, pb, total):
    global ans
    if s == "a":
        total += a[pa]
        if total > k:
            ans = max(ans, pa + pb)
            return
        pa += 1
    else:
        total += b[pb]
        if total > k:
            ans = max(ans, pa + pb)
            return
        pb += 1
    if pa < n:
        shouka("a", pa, pb, total)
    if pb < m:
        shouka("b", pa, pb, total)

    ans = max(ans, pa+pb)


shouka("a", 0, 0, 0)
shouka("b", 0, 0, 0)
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])

ptr = m
ans = 0

for i in range(n + 1):
    if a[i] > k:
        break
    while a[i] + b[ptr] > k:
        ptr -= 1
    ans = max(ans, i + ptr)

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


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

for i in range(n):
    A[i+1] = A[i] +a[i]

B = [0]*(m+1)
for j in range(m):
    B[j+1] = 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(ans, i+j)
print(ans)
# Original solution
import bisect
N,M,K=list(map(int,input().split()))
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))

sum_alist=[0]
for i in range(N):
  sum_alist.append(sum_alist[-1]+alist[i])
#print(sum_alist)

sum_blist=[0]
for i in range(M):
  sum_blist.append(sum_blist[-1]+blist[i])
#print(sum_blist)

limit_a=bisect.bisect(sum_alist,K)
#print(limit_a)

limit_b=bisect.bisect(sum_blist,K)
#print(limit_b)

answer=0
for i in reversed(list(range(1,limit_a))):
  a_sum=sum_alist[i]
  b_sum=K-a_sum
  pos_b=bisect.bisect(sum_blist,b_sum)
  #print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
  answer=max(answer,i+pos_b-1)

for i in reversed(list(range(1,limit_b))):
  b_sum=sum_blist[i]
  a_sum=K-b_sum
  pos_a=bisect.bisect(sum_alist,a_sum)
  #print(i,pos_b-1,a_sum,sum_blist[pos_b-1],b_sum)
  answer=max(answer,i+pos_a-1)
  
if limit_a==1:
  pos_b=bisect.bisect(sum_blist,K)
  answer=pos_b-1
elif limit_b==1:
  pos_a=bisect.bisect(sum_alist,K)
  answer=pos_a-1
  
print(answer)

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

sum_alist=[0]
for a in alist:
  sum_alist.append(sum_alist[-1]+a)
sum_blist=[0]
for b in blist:
  sum_blist.append(sum_blist[-1]+b)
  
index_b=M
answer=0
for i in range(N+1):
  sum_a=sum_alist[i]
  if sum_a>K:
    break
    
  while sum_a+sum_blist[index_b]>K:
    index_b-=1
    
  #print(i,index_b)
  answer=max(answer,i+index_b)
  
print(answer)
# Original solution
N, M, K = list(map(int, input().split()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))


def cumsum(l):
    s = 0
    for v in l:
        s += v
        yield s


a = (0,) + tuple(cumsum(A))
b = (0,) + tuple(cumsum(B))
ans = 0
m = M
for i in range(N + 1):
    if a[i] > K:
        continue
    for j in range(m, -1, -1):
        if a[i] + b[j] <= K:
            k = j
            break
        else:
            continue
    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()))


def cumsum(l):
    s = 0
    for v in l:
        s += v
        yield s


a = [0] + list(cumsum(A))
b = [0] + list(cumsum(B))
ans = 0
n = N + 1
m = M
for i in range(n):
    if a[i] > K:
        continue
    for j in range(m, -1, -1):
        if a[i] + b[j] <= K:
            m = j
            break
        else:
            continue
    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()))


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
a.insert(0,0)
b = Cum(B)
b.insert(0,0)

na = 0
for i in range(N+1):
    if i == N and a[i]<=K:
        na = N
    elif a[i]<=K and a[i+1]>K:
        na = i

ans = na

nb = 0
for i in range(na,-1,-1):
    temp = K-a[i]
    for j in range(nb,M+1):
        if j == M and b[j] <= temp:
            nb = M
        elif b[j]<=temp and b[j+1]>temp:
            nb = j
        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()))


def Cum(X):
    temp = 0
    Cum = [0]*len(X)
    for i in range(len(X)):
        temp += X[i]
        Cum[i] += temp
    return Cum

a = Cum(A)
a.insert(0,0)
b = Cum(B)
b.insert(0,0)

na = 0
for i in range(N+1):
    if i == N and a[i]<=K:
        na = N
    elif a[i]<=K and a[i+1]>K:
        na = i

ans = na

nb = 0
for i in range(na,-1,-1):
    temp = K-a[i]
    for j in range(nb,M+1):
        if j == M and b[j] <= temp:
            nb = M
            ans = max(ans,i+nb)
        elif b[j]<=temp and b[j+1]>temp:
            nb = j
            ans = max(ans,i+nb)
            break
        
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.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,len(a)):
    sum_a.append(sum_a[i-1] + a[i])
    if sum_a[i] > k:
        break

sum_b = [0]
for i in range(1,len(b)):
    sum_b.append(sum_b[i-1] + b[i])
    if sum_b[i] > k:
        break

ans = 0
for i in range(len(sum_a)):
    if sum_a[i] > k:
        break
    for j in range(len(sum_b)-1,-1,-1):
        if sum_a[i] + sum_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.insert(0,0)
b.insert(0,0)

sum_a = [0]
for i in range(1,n+1):
    sum_a.append(sum_a[i-1] + a[i])

sum_b = [0]
for i in range(1,m+1):
    sum_b.append(sum_b[i-1] + b[i])

ans = 0
for i in range(n+1):
    if sum_a[i] > k:
        break
    for j in range(m,-1,-1):
        if sum_a[i] + sum_b[j] <= k:
            ans = max(ans, i+j)
            m = j
            break
print(ans)
# Original solution
N,M,K=list(map(int,input().split()))
A,B=[0],[0]
A+=list(map(int,input().split()))
B+=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
for i in range(N+1):
    if A[i]>K:
        break
    for j in range(M+1):
        if A[i]+B[j]>K:
            break
        ans=max(ans,i+j)

print(ans)


# Optimized solution
N,M,K=list(map(int,input().split()))
A,B=[0],[0]
A+=list(map(int,input().split()))
B+=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,j=0,M
for i in range(N+1):
    if A[i]>K:
        break
    while j>0 and 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,B=[0],[0]
A+=list(map(int,input().split()))
B+=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,j=0,M
for i in range(N+1):
    if A[i]>K:
        break
    while j>0 and A[i]+B[j]>K:
        j-=1
    ans=max(ans,i+j)

print(ans)


# Optimized solution
N,M,K=list(map(int,input().split()))
A,B=[0],[0]
A+=list(map(int,input().split()))
B+=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,j=0,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
from collections import deque
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)

# Optimized solution
from itertools import accumulate
from bisect import bisect
n,m,k=list(map(int,input().split()))
A=list(map(int,input().split()))
A=list(accumulate(A,initial=0))
B=list(map(int,input().split()))
B=list(accumulate(B))

ans = 0
for i,a in enumerate(A):
  if a > k: break
  ans = max(ans,i + bisect(B,k-a))
print(ans)
# Original solution
from itertools import accumulate


def binary(N, T):  # 二分探索 # N:探索要素数
    l, r = -1, N + 1
    while r - l > 1:
        if T < b[(l + r) // 2]:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r - 1


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

ans = 0
for i, ai in enumerate(a):
    t = k - ai
    if t >= 0:
        j = binary(m, t)
        ans = max(ans, i + j)
print(ans)


# Optimized solution
from itertools import accumulate


def binary(N, T):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if T < b[(l + r) // 2]:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r - 1


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

ans = 0
for i, ai in enumerate(a):
    t = k - ai
    if t >= 0:
        j = binary(m + 1, t)
        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()))

sa = {0: 0}
for i, val in enumerate(A):
  sa[i+1] = sa[i] + val

sb = {0: 0}
for i, val in enumerate(B):
  sb[i+1] = sb[i] + val

max_num = 0

for i in range(N+1):
  if(sa[i]>K):
    break
  for j in range(M+1):
    if(sb[M-j]<=K-sa[i]):
      break
  max_num = max(max_num,i+M-j)

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

sa = [0]
for i, val in enumerate(A):
  sa.append(sa[i] + val)

sb = [0]
for i, val in enumerate(B):
  sb.append(sb[i] + val)

max_num = 0
ind_max = M
for i in range(N+1):
  if(sa[i]>K):
    break
  c = 0
  for k in range(ind_max+1):
    if(sb[ind_max-k]<=K-sa[i]):
      break
    c += 1
  ind_max -= c
  max_num = max(max_num,i+ind_max)

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


A_cs = [0]*(len(A)+1)
for i in range(1,len(A)+1):
    A_cs[i] = A_cs[i-1]+ A[i-1]

B_cs = [0]*(len(B)+1)
for i in range(1,len(B)+1):
    B_cs[i] = B_cs[i-1]+ B[i-1]

total = 0
for i in range(len(A_cs)):
    for j in range(len(B_cs)):
        if A_cs[i]+B_cs[j]<=K:
            if total < i+ j:
                total = i+ j

print(total)

# Optimized solution
N, M, K = list(map(int, input().split()))
A = [0]+list(map(int, input().split()))
B = [0]+list(map(int, input().split()))
import itertools
A_cs = list(itertools.accumulate(A))
B_cs = list(itertools.accumulate(B))

total = 0
j = len(B)-1
for i in range(len(A_cs)):
    while (j >= 0):
        if A_cs[i] + B_cs[j] <= K:
                total = max(total,i + j)
                break
        j -= 1

print(total)
# Original solution
n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().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=0

for i in range(n+1):
  j=0
  if A[i]>k:
    break
  nokori=k-A[i]

  while(B[j]<=nokori and j<m):
    j+=1

  if nokori<B[j]:
    j-=1
    
  ans=max(ans,i+j)
print(ans)


# Optimized solution
n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().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):
  # j=m
  if A[i]>k:
    break
  nokori=k-A[i]

  while(nokori<B[j] and 0<=j):
    j-=1

    
  ans=max(ans,i+j)
print(ans)
# Original solution
n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().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):
  j=m
  if A[i]>k:
    break
  nokori=k-A[i]

  while(nokori<B[j] and 0<=j):
    j-=1

    
  ans=max(ans,i+j)
print(ans)


# Optimized solution
n,m,k=[int(x) for x in input().rstrip().split()]
a=[int(x) for x in input().rstrip().split()]
b=[int(x) for x in input().rstrip().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=0

for i in range(n+1):
  # j=0
  if A[i]>k:
    break
  nokori=k-A[i]

  while(B[j]<=nokori and j<m):
    j+=1

  if nokori<B[j]:
    j-=1
    
  ans=max(ans,i+j)
print(ans)
# Original solution
n, m, k = input().split()
a = input().split()
b = input().split()

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

ans = 0
temp_a = {}
temp_b = {}

for i_a in range(n+1):
  if sum(a[0:i_a]) > k:
    break
  temp_a[i_a] = sum(a[0:i_a])
for i_b in range(m+1):
  if sum(b[0:i_b]) > k:
    break
  temp_b[i_b] = sum(b[0:i_b])
  
temp_a = sorted(list(temp_a.items()), key=lambda x:x[1], reverse=True)
temp_b = sorted(list(temp_b.items()), key=lambda x:x[1], reverse=True)
ans = {}

if len(temp_a) > len(temp_b):
  temp_a, temp_b = temp_b, temp_a
  n, m = m, n

for item_a in temp_a:
  for item_b in temp_b:
    if item_a[1] + item_b[1] > k:
      continue
    else:
      ans[len(ans)] = item_a[0] + item_b[0]
      break

ans = max(ans.values())
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 a[i] + b[j] > k:
    j -= 1
  ans = max(ans, i+j)

print(ans)
# Original solution
import itertools

N, M, K = list(map(int, input().split()))
A, B = [], []
A = list(map(int, input().split()))
B = list(map(int, input().split()))
max_books = 0
order_list = set(list(itertools.permutations(['A']*N + ['B']*M)))
for order in order_list:
  ia, ib = 0, 0
  time = 0
  books = 0
  for which in order:
    books += 1
    if which == 'A':
      time += A[ia]
      ia += 1
    else:
      time += B[ib]
      ib += 1
    if time == K:
      max_books = max(max_books, books)
      break
    if time > K:
      max_books = max(max_books, books-1)
      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()))
def HowManyBooks(A, B):
  A_sum, B_sum = [0], [0]
  for i in range(N):
    A_sum.append(A_sum[i] + A[i])
  for i in range(M):
    B_sum.append(B_sum[i] + B[i])
    books = 0
  for i in range(N+1):
    if A_sum[i] > K:
      break
    rest = K - A_sum[i]
    for j in range(M+1):
      if rest == B_sum[j]:
        books = max(books, i+j)
        break
      elif rest < B_sum[j]:
        books = max(books, i+j-1)
        break
    
  return books
print((HowManyBooks(A, B)))
# Original solution
import itertools
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

answer = -float('inf')
order = list(itertools.permutations([1]*n+[0]*m))
order2 = set(order)
for o in order2:
  acur, bcur = 0, 0
  books = 0
  time = 0
  for i in o:
    books += 1
    if i:
      time += a[acur]
      acur += 1
    else:
      time += b[bcur]
      bcur += 1
    if time == k:
      answer = max(answer, books)
      break
    elif time > k:
      answer = max(answer, books-1)
      break
print(answer)

# Optimized solution
import itertools
n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [sum(a[0:i]) for i in range(n+1)]
bb = [sum(b[0:i]) for i in range(m+1)]
ab = [list(range(n+1)), list(range(m+1))]
candidate = list(itertools.product(*ab))
answer = -1
for can in candidate:
  time = aa[can[0]] + bb[can[1]]
  if time <= k:
    answer = max(answer, can[0]+can[1])
print(answer)
# Original solution
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    if la[i] + a[i] > k:
        break
    la.append(la[i]+a[i])
for j in range(m):
    if lb[j] + b[j] > k:
        break
    lb.append(lb[j]+b[j])
for l in range(len(la)):
    cnt = l
    q = 0
    p = 0
    while la[l] + p <= k:
        q += 1
        if q == len(lb):
            cnt += len(lb)-1
            break
        p = lb[q] 
    if cnt == l:
        cnt += q - 1
    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()))
la = [0]
lb = [0]
mx = 0
for i in range(n): 
    if la[i] + a[i] > k:
        break
    la.append(la[i]+a[i])
for j in range(m):
    if lb[j] + b[j] > k:
        break
    lb.append(lb[j]+b[j])
now = len(lb)-1
for l in range(len(la)):
    cnt = l
    q = now
    while la[l] + lb[q] > k:
        q -= 1
    now = q
    cnt += q
    if cnt > mx:
        mx = cnt
print(mx)
# Original solution
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
from bisect import bisect
for i in range(n+1):
    ALL = a[i]
    if ALL > k:
        continue
    else:
        idx = bisect(b,k-ALL)
    #print(i,ALL,idx)
        ans = max(ans,i+idx-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()))
for i in range(1,n):
    a[i] += a[i-1]
for i in range(1,m):
    b[i] += b[i-1]
a = [0]+a
b = [0]+b

ans = 0
ALL = 0
j = m

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

ans = 0
ALL = 0
j = m

for i in range(n+1):
    if a[i] > k:
        continue
    else:
        while k-a[i] < b[j] :
            j -=1
    ans = max(ans,i+j)
print(ans)

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

from itertools import accumulate

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

ans = 0
num = b
for i in range(a+1):
    if A[i] > k:
        continue
    while True :
        if A[i] + B[num] > k:
            num -=1
        else:
            ans = max(ans,i+num)
            break
print(ans)
# Original solution
n, m, k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

total = 0
count = 0
flag = n-1
for i in range(n):
    total += a[i]
    if total > k:
        total -= a[i]
        flag = i-1
        break
    count += 1
ans = count
for i in range(m):
    if b[i] > k:
        break
    total += b[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= a[flag]
            flag -= 1
            count -= 1
    if total > k: 
        break
    ans = max(ans, count)

total = 0
count = 0
flag = m-1
for i in range(m):
    total += b[i]
    if total > k:
        total -= b[i]
        flag = i-1
        break
    count += 1
for i in range(n):
    if a[i] > k:
        break
    total += a[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= b[flag]
            flag -= 1
            count -= 1
    if total > k: 
        break
    ans = max(ans, count)


print(ans)

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

total = 0
count = 0
flag = n-1
for i in range(n):
    total += a[i]
    if total > k:
        total -= a[i]
        flag = i-1
        break
    count += 1
ans = count
for i in range(m):
    if b[i] > k:
        break
    total += b[i]
    count += 1
    while total > k:
        if flag == -1:
            break
        else:
            total -= a[flag]
            flag -= 1
            count -= 1
    if total > k: 
        break
    ans = max(ans, count)

print(ans)