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()))
cntA = 0
ans = 0
p = max(m,n)
if p == n:
  q = a
  r = b
else:
  q = b
  r = a
for i in range(p):
  if cntA+q[i] > k:
    break
  ans += 1
  cntA += q[i]
indA = ans-1
nc = indA+1
for j in range(indA+1):
  temp = 0
  adds = 0
  for v in r:
    adds += v
    if cntA + adds > k:
      break
    temp += 1
  cntA -= q[nc-1-j]
  ans = max(ans,indA+1+temp)
  indA -= 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,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]+a[i]>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,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]+a[i]>k:
    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,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,bi = 0,m
for i in range(n+1):
  for j in range(bi,-1,-1):
    if a[i]+b[j]<=k:
      ans = max(ans,i+j)
      bi = j
      break
print(ans)
# Original solution
import bisect
import sys

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

a_accumulated = [0] * (n + 1)
b_accumulated = [0] * (m + 1)

for idx, a in enumerate(A):
    a_accumulated[idx + 1] = a_accumulated[idx] + a # idx == 0の場合はa_accumulated[-1]を参照するが、それは0初期化されているので問題ない。

for idx, b in enumerate(B):
    b_accumulated[idx + 1] = b_accumulated[idx] + b

a_limit = bisect.bisect(a_accumulated, k)
if a_limit == 0:
    position = bisect.bisect(b_accumulated, k)
    print((position - 1))
    sys.exit(0)

best_num = 0
for i in reversed(list(range(0, a_limit))):
    position = bisect.bisect_right(b_accumulated, k - a_accumulated[i])
    best_num = max(best_num, i + position - 1)
print(best_num)



# Optimized solution
import bisect
import sys

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

a_accumulated = [0] * (n + 1)
b_accumulated = [0] * (m + 1)

for idx, a in enumerate(A):
    a_accumulated[idx + 1] = a_accumulated[idx] + a

for idx, b in enumerate(B):
    b_accumulated[idx + 1] = b_accumulated[idx] + b

a_limit = bisect.bisect(a_accumulated, k)
if a_limit == 0:
    position = bisect.bisect(b_accumulated, k)
    print((position - 1))
    sys.exit(0)

best_num = 0
for i in reversed(list(range(0, a_limit))):
    position = bisect.bisect_right(b_accumulated, k - a_accumulated[i])
    best_num = max(best_num, i + position - 1)
print(best_num)
# Original solution
import sys

sys.setrecursionlimit(200000000)

N, M, K = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
max_num = 0

def dfs(curr_a, curr_b, choice, time_required, count):
    global max_num
    if choice == 0:
        if curr_a >= N - 1:
            if max_num < count:
                max_num = count
            return
        else:
            curr_a += 1
            time_required += a[curr_a]
    else:
        if curr_b >= M - 1:
            if max_num < count:
                max_num = count
            return
        else:
            curr_b += 1
            time_required += b[curr_b]
    if time_required > K:
        return
    count += 1
    if max_num < count:
        max_num = count
    dfs(curr_a, curr_b, 0, time_required, count)
    dfs(curr_a, curr_b, 1, time_required, count)


if sum(a) + sum(b) <= K:
    print((N + M))
else:
    curr_a = -1
    curr_b = -1
    time_required = 0
    count = 0
    dfs(curr_a, curr_b, 0, time_required, count)
    curr_a = -1
    curr_b = -1
    time_required = 0
    count = 0
    dfs(curr_a, curr_b, 1, time_required, count)
    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()))
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
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l

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

ca = cumsum(a)
cb = cumsum(b)

def sub(x):
    res = float("inf")
    for i in range(x+1):
        if i>n or (x-i)>m:
            continue
        res = min(res, ca[i] + cb[x-i])
    return res<=k
l = 0
r = n+m+1
while l+1<r:
    mm = (l+r)//2
    if sub(mm):
        l = mm
    else:
        r = mm
print(l)

# Optimized solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def cumsum(a):
    """l[i] = sum(a[:i]) なるlを返す
    sum(a[i:j]) == l[j+1] - l[i]
    """
    c = 0
    l = [None] * (len(a)+1)
    for i,num in enumerate(a):
        l[i] = c
        c += num
    l[-1] = c
    return l

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

r = m-1
s = sum(b)
num = m
best = 0
while s>k and r>=0:
    s -= b[r]
    r -= 1
    num -= 1
if s<=k:
    best = max(best, num)
for l in range(n):
    num += 1
    s += a[l]
    while s>k and r>=0:
        s -= b[r]
        r -= 1
        num -= 1
    if s<=k:
        best = max(best, num)
print(best)
# Original solution
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(eval(input()))
def rm():
    return list(map(int,input().split()))
def rl():
    return list(map(int,input().split()))

'''C Tsundoku'''
def count(i,n,j,m,a,b,k):
    if k<0:
        return -1
    if i==n and j==m:
        return 0
    if i==n:
        if b[j]<=k:
            return 1+count(i,n,j+1,m,a,b,k-b[j])
        return 0
    if j==m:
        if a[i]<=k:
            return 1+count(i+1,n,j,m,a,b,k-a[i])
        return 0
    return max(1+count(i,n,j+1,m,a,b,k-b[j]),1+count(i+1,n,j,m,a,b,k-a[i]))

n,m,k=rm()
a=rl()
b=rl()
i=0;j=0;
print((count(i,n,j,m,a,b,k)))

# Optimized solution
import sys
import math
import heapq
from collections import defaultdict, deque
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
def r():
    return int(eval(input()))
def rm():
    return list(map(int,input().split()))
def rl():
    return list(map(int,input().split()))

'''C Tsundoku'''
n,m,k=rm()
a=rl()
b=rl()
c=[0]*(n+1)
d=[0]*(m+1)
for i in range(n):
    c[i+1]=c[i]+a[i]
for i in range(m):
    d[i+1]=d[i]+b[i]
ans=0;j=m
for i in range(n+1):
    if c[i]>k:
        break
    while c[i]+d[j]>k:
        j-=1
    ans=max(ans,i+j)
print(ans)
# Original solution
import heapq
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

na = 0
nb = 0
t = 0
b = 0
hq = []
heapq.heappush(hq,(t, na, nb))

while hq:
  t, na, nb = heapq.heappop(hq)
  if (na < N) and (t + A[na] <= K):
    heapq.heappush(hq,(t + A[na], na + 1, nb))
    b = max(b,na + nb + 1)
  if (nb < M) and (t + B[nb] <= K):
    heapq.heappush(hq,(t + B[nb], na, nb + 1))
    b = max(b,na + nb + 1)
#
print(b)





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

TA = [0]
TB = [0]
na = 0
nb = 0

for i in range(N):
  n = TA[-1]+A[i]
  if n > K:
    break
  TA.append(n)
  na = i + 1
#
for i in range(M):
  n = TB[-1]+B[i]
  if n > K:
    break
  TB.append(n)
  nb = i + 1
#
a = 0
ans = 0

for b in range(nb,-1,-1):
  while TB[b]+TA[a] <= K:
    ans = max(ans,a+b)
    a += 1
    if a > na:
      a -= 1
      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()))

Asum=[0]
Bsum=[0]

for i in range(N):
    Asum.append(Asum[-1]+A[i])
    if Asum[i]>K:
        break
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    if Bsum[i]>K:
        break
    
m=0
for i in range(len(Asum)):
    for j in range(len(Bsum)):
        if Asum[i]+Bsum[j]<=K and m<i+j:
            m=i+j
print(m)
        

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

for i in range(N):
    Asum.append(Asum[-1]+A[i])
        
for i in range(M):
    Bsum.append(Bsum[-1]+B[i])
    
m=0
j=M

for i in range(len(Asum)):
    if Asum[i]>K:
        break
    while Asum[i]+Bsum[j]>K:
        j-=1
    if m<i+j:
        m=i+j
        
print(m)
# 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])
 
num,x = 0,m
 
for i in range(len(a)+1):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)
 
 

# 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])
 
num,x = 0,m
 
for i in range(len(A)):
  if A[i] > k:
    break
  while A[i] + B[x] > k:
    x -= 1
  num = max(num, i + x)
  
print(num)
# 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]
T = 0
ans = 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):
  for j in range(M+1):
    T = a[i] + b[j]
    if T <= K:
      ans = max(ans, (i + j))
    else:
      pass


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]
T = 0
ans = 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 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()))

cost = [[float('inf')]*(m+1) for i in range(n+1)]
#Aからi冊、Bからｊ冊読むときにかかる時間がcost[i][j]
              
cost[0][0] = 0
max_count = 0

i = 0
while i<=n:
  j = 0
  while j<m:
    cost[i][j+1] = cost[i][j] + b[j]
    j += 1
    if cost[i][j]<=k:
      max_count = max(max_count,i+j)
    else:
      break
  if i == n:
    break
  cost[i+1][0] = cost[i][0] + a[i]
  i += 1
  if cost[i][0]<=k:
    max_count = max(max_count,i)
  else:
    break
print(max_count)

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

cost = {}#[[float('inf')]*(m+1) for i in range(n+1)]
#Aからi冊、Bからｊ冊読むときにかかる時間がcost[i][j]
              
cost[(0,0)] = 0
max_count = 0

i = 0
while i<=n:
  j = 0
  while j<m:
    cost[(i,j+1)] = cost[(i,j)] + b[j]
    j += 1
    if cost[(i,j)]<=k:
      max_count = max(max_count,i+j)
    else:
      break
  if i == n:
    break
  cost[(i+1,0)] = cost[(i,0)] + a[i]
  i += 1
  if cost[(i,0)]<=k:
    max_count = max(max_count,i)
  else:
    break
print(max_count)
# Original solution
def main():
    N, M, K = list(map(int, input().split()))
    *A, = list(map(int, input().split()))
    *B, = list(map(int, input().split()))

    s = 0
    j = 0
    while j < len(B) and s + B[j] <= K:
        s += B[j]
        j += 1

    ans = cnt = j

    j -= 1
    for x in A:
        while j >= 0 and s + x > K:
            s -= B[j]
            j -= 1
            cnt -= 1
        if s + x > K:
            break
        s += x
        cnt += 1
        if ans < cnt:
            ans = cnt
    print(ans)


if __name__ == '__main__':
    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()))

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    *A, = accumulate(A)
    *B, = accumulate(B)

    ans = 0
    j = M

    for i, x in enumerate(A):
        if x > K: break
        while B[j] > K - x: j -= 1
        ans = max(ans, i + j)

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

    def accumulate(a):
        s = 0
        yield s
        for x in a:
            s += x
            yield s

    A = accumulate(A)
    *B, = accumulate(B)

    ans = 0
    j = M

    for i, x in enumerate(A):
        if x > K: break
        while B[j] > K - x: j -= 1
        ans = max(ans, i + j)

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    from itertools import chain

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

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
n, m, k = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans = 0

for i in range(n + 1): # 0を最初に代入した分
    if A_cumsum[i] > k:
        break
    for j in range(m + 1):
        if A_cumsum[i] + B_cumsum[j] > k:
            break
        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_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans, j = 0, m

for i in range(n + 1): # 0を最初に代入した分
    if A_cumsum[i] > k:
        break
    while A_cumsum[i] + B_cumsum[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()))
AS=[0]
BS=[0]
r=0
for i in A:
  AS.append(i+AS[-1])
for i in B:
  BS.append(i+BS[-1])
p=n+m+2
f=m+2
for i in range(1,n+2):
  for j in range(1,f):
    if AS[-i]+BS[-j]<=k:
      r=max(r,p-i-j)
      f=j
      break
print(r)

# Optimized solution
n,m,k=list(map(int,input().split()))
A=list(map(int,input().split()))
B=list(map(int,input().split()))
AS=[0]
BS=[0]
r=0
for i in A:
  if i+AS[-1]<=k:
    AS.append(i+AS[-1])
  else:
    break
    
for i in B:
  if i+BS[-1]<=k:
    BS.append(i+BS[-1])
  else:
    break
    
j=len(BS)-1
for i in range(len(AS)):
  while AS[i]+BS[j]>k:
    j-=1
  r=max(r,i+j)
print(r)
# Original solution
m, n, k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

def check_(lis, num, ti):
    ans = 0
    for i in range(num+1):
        if ans >= ti:
            break
        ans +=  lis[i]
    return i

max_a = check_(a, m, k)
max_b = check_(b, n, k)
ans = 0
for i in range(max_a+1):
    for j in range(max_b+1):
        if sum(a[:i+1]) + sum(b[:j+1]) <= k and i + j > ans:
            ans = i+j 
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(2,n+1):
    A[i] += A[i-1]
for i in range(2,m+1):
    B[i] += B[i-1]

j = m
ans = 0
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 sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
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(0,n+1):
	curr=a[i]
	j=m
	if curr>k:
		break
	while(b[j]>k-curr):
		j-=1
	ans=max(ans,i+j)
print(ans)



# Optimized solution
from sys import stdin
input = lambda: stdin.readline().rstrip("\r\n")
from collections import defaultdict as vector, deque as que
read = lambda: list(map(int,input().split()))
from bisect import bisect
from heapq import heappush as hpush,heappop as hpop

n,m,k=read()
A=read()
B=read()
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;j=m
for i in range(0,n+1):
	curr=a[i]
	if curr>k:
		break
	while(b[j]>k-curr):
		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()))
num = min(N,M)
C= [None]*(num*2)
C[::2] = A[:num]
C[1::2] = B[:num]
C.extend(A[num:])
C.extend(B[num:])
if N>M:
  C.extend(A[N-M:N])
elif M>N:
  C.extend(B[M-N:M])
  
if min(C[0],C[1])>K:
  print('0')
  exit()
k=0
ans=0
for i in range(len(C)):
  key=min(C[0],C[1])
  k+=key
  ans+=1
  C.remove(key)
  if k>=K:
    break
  if len(C)==1:
    k+=C[0]
    ans+=1
    break
if k==K:
  print(ans)
else:
  print((ans-1))

# 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
  else:
    while b[j] > K - a[i]:
      j -= 1
  ans = max(ans, i + j)
print(ans)
# Original solution
import sys


def input(): return sys.stdin.readline().strip()


def main():
    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, 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(len(a)):
        if a[i] > K:
            break
        while a[i] + b[j] > K:
            j -= 1
        ans = max(ans, i + j)

    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    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, 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(len(a)):
        if a[i] > K:
            break
        while a[i] + b[j] > K:
            j -= 1
        ans = max(ans, i + j)

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
N, M, K = list(map(int, input().split(" ")))
A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))
max = 0
for i in range(len(A)+1):
  time_a = 0
  if i > 0:
    time_a = sum(A[:i])
  if time_a > K:
    break
  for j in range(len(B)+1):
    time = time_a
    if j > 0:
    	time += sum(B[:j])
    if time > K:
      break
    elif max < i+j:
      max = i+j
print(max)

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

sumA = [0] * (N+1)
sumB = [0] * (M+1)
for i in range(N):
  sumA[i+1] = sumA[i] + A[i]
for i in range(M):
  sumB[i+1] = sumB[i] + B[i]

b_i = M
max_count = 0
for i in range(N+1):
  a = sumA[i]
  if a > K:
    continue
  if b_i>0:
    while a + sumB[b_i] > K:
      b_i -= 1
      if b_i==0:
        break
  max_count = max(max_count, i + b_i)
print(max_count)
# 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]
for i in range(N):
    sumA.append(sumA[i] + A[i])
for i in range(M):
    sumB.append(sumB[i] + B[i])

#print(sumA)
    
#sumA = list(itertools.accumulate(A))
#sumB = list(itertools.accumulate(B))
ans=0
j=M
for i in range(N+1):
    if sumA[i]>K:
        break
    #j-=1
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    if i==0:
        best=j
    ans=max(ans,i+j)
    j=best
print(ans)

# Optimized solution
import itertools

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

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
j=M-1
while K<sumB[j] and j>=0:
    j-=1
ans=j+1
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

INF = float('inf')
# dp[n][m] represents total time took to read top n book from A and top m book from B
dp = [[INF] * (M+1) for _ in range(N+1)]
dp[0][0] = 0

count = 0
for i in range(N):
    dp[i+1][0] = dp[i][0] + A[i]
    if dp[i+1][0] > K:
        break
    else:
        count = max(count, i+1)

for i in range(N+1):
    for j in range(M):
        dp[i][j+1] = dp[i][j] + B[j]
        if dp[i][j+1] > K:
            break
        else:
            count = max(i + j + 1, count)

print(count)

# Optimized solution
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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


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

print(count)
# Original solution
import bisect
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,len(A)):
    A[i]+=A[i-1]
for i in range(1,len(B)):
    B[i]+=B[i-1]

honn=bisect.bisect(B,K)
#print(honn)
for i in range(len(A)):
    s=K-A[i]
    if s>=0:
        
        a=bisect.bisect(B,s)
        #print(s)
        if i+1+a>honn:
            honn=i+1+a
print(honn)

# Optimized solution
import bisect
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,len(A)):
    A[i]+=A[i-1]
for i in range(1,len(B)):
    B[i]+=B[i-1]
honn=a=bisect.bisect(B,K)
for i in range(len(A)):
    s=K-A[i]
    if s>=0:
        a=bisect.bisect(B,s)
        if i+1+a>honn:
            honn=i+1+a
print(honn)