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

b2=[]
b2.append(0)
for i in range(1,m+1):
  b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
  j=m
  a_sum+=a[i]
  while True:
    if k>=a_sum+b2[j]:
      cnt=max(cnt,i+j)
      break
    j-=1
    if j <0:
      break
print(cnt)

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

b2=[]
b2.append(0)
for i in range(1,m+1):
  b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
  j=m
  a_sum+=a[i]
  while True:
    if k>=a_sum+b2[j]:
      cnt=max(cnt,i+j)
      m=j
      break
    j-=1
    if j <0:
      break
print(cnt)
# Original solution
import sys
sys.setrecursionlimit(4100000)

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

ans_cand = []

def dfs(a_i, b_i, ans, time):
    if time == K:
        ans_cand.append(ans)
        return 0

    if time > K:
        ans_cand.append(ans - 1)
        return 0

    if a_i < N:
        dfs(a_i + 1, b_i, ans + 1, time + A[a_i])
    if b_i < M:
        dfs(a_i, b_i + 1, ans + 1, time + B[b_i])
    return 0


dfs(0, 0, 0, 0)

print((max(ans_cand)))


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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans = 0
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
from sys import stdin

def main():
    n, m, k = [int(x) for x in stdin.readline().rstrip().split()]

    pileda = 0
    a = [0]
    for x in stdin.readline().rstrip().split():
        x = int(x)
        pileda += x
        a.append(pileda)
    
    piledb = 0
    b = [0]
    for x in stdin.readline().rstrip().split():
        x = int(x)
        piledb += x
        b.append(piledb)

    ans = 0
    for ai, at in enumerate(a):
        if at > k:
            break

        bi = m
        while at + b[bi] > k:
            bi -= 1
        
        ans = max(ans, ai+bi)
    
    print(ans)
            

if __name__ == "__main__":
    main()

# Optimized solution
from sys import stdin

def main():
    n, m, k = [int(x) for x in stdin.readline().rstrip().split()]

    pileda = 0
    a = [0]
    for x in stdin.readline().rstrip().split():
        x = int(x)
        pileda += x
        a.append(pileda)
    
    piledb = 0
    b = [0]
    for x in stdin.readline().rstrip().split():
        x = int(x)
        piledb += x
        b.append(piledb)

    ans = 0
    bi = m
    for ai, at in enumerate(a):
        if at > k:
            break

        while at + b[bi] > k:
            bi -= 1
        
        ans = max(ans, ai+bi)
    
    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()))

tmp = 0
aa = [0]*(n+1)
for i in range(n):
    tmp += a[i]
    aa[i+1] = tmp

tmp = 0
bb = [0]*(m+1)
for i in range(m):
    tmp += b[i]
    bb[i+1] = tmp

j = m
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k-aa[i] and j >= 0:
        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()))

aa = [0]*(n+1)
for i in range(n):
    aa[i+1] = aa[i] + a[i]

bb = [0]*(m+1)
for i in range(m):
    bb[i+1] = bb[i] + b[i]

j = m
ans = 0
for i in range(n+1):
    if aa[i] > k:
        break
    while bb[j] > k-aa[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)
# Original solution
from collections import deque
def resolve():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    read = deque()
    w = 0

    if sum(A) + sum(B) <= K:
        print((len(A) + len(B)))
        return

    while w <= K:        
        if len(A) == 0 and len(B) == 0:
            break

        if len(A) == 0:
            if w + B[0] <= K:
                read.append(B[0])
                w += B[0]
            B.pop(0)
            continue

        if len(B) == 0:
            if w + A[0] <= K:
                read.append(A[0])
                w += A[0]
            A.pop(0)
            continue

        if A[0] < B[0] or len(B) == 0:
            if w + A[0] <= K:
                read.append(A[0])
                w += A[0]
            A.pop(0)
        else:
            if w + B[0] <= K:
                read.append(B[0])
                w += B[0]
            B.pop(0)

    print((len(read)))


resolve()


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

    ans = 10 ** 10
    t = 0

    for i in range(M):
        t += B[i]
    j = M
    ans = 0
    for i in range(N+1):
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        
        if t > K:
            break
        
        ans = max(ans, i+j)
        
        if i == N:
            break
        t += A[i]
    
    print(ans)

resolve()
# Original solution
N, M, K = [int(x) for x in input().split(' ')]
A = [int(x) for x in input().split(' ')]
B = [int(x) for x in input().split(' ')]

# N, M, K = [int(x) for x in [2e3, 2e3, 1e9]]
# A = [int(x) for x in range(N)]
# B = [int(x) for x in range(M)]

stack = [[0, 0, 0, 0]]
ans = 0
while len(stack):
  s = stack[-1]
  stack.pop()

  count = s[3]
  a = count 
  b = count
  i = s[0]
  j = s[1]
  time = s[2]

  if i > N - 1 and j > M - 1:
    ans = max(ans, count)
    continue
  if time > K:
    ans = max(ans, count - 1)
    continue

  if i < N:
    stack.append([i + 1, j, time + A[i], count + 1])
  if j < M:
    stack.append([i, j + 1, time + B[j], count + 1])

print(ans)

# Optimized solution
N, M, K = [int(x) for x in input().split(' ')]
A = [int(x) for x in input().split(' ')]
B = [int(x) for x in input().split(' ')]

# N, M, K = [int(x) for x in [2e3, 2e3, 1e9]]
# A = [int(x) for x in range(N)]
# B = [int(x) for x in range(M)]

A_deep = 0
B_deep = 0
time = 0
while A_deep < N:
  if K >= time + A[A_deep]:
    time += A[A_deep]
    A_deep += 1
  else:
    break 
while B_deep < M:
  if K >= time + B[B_deep]:
    time += B[B_deep]
    B_deep += 1
  else:
    break 

i = A_deep - 1
j = B_deep
ans = i + j + 1
while i >= 0 and j < M:
  while i >= 0:
    time -= A[i]
    i -= 1
    if K - time >= B[j]:
      break 
  while j < M:
    if K >= time + B[j]:
      time += B[j]
      j += 1
      ans = max(ans, i + j + 1)
    else: 
      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()))

mmax = 0
pre = False
num = 0
ans = 0
ans2 = 0
for i in range(N+1):
  if i == 0:
    ans = 0
  else:
    ans += A[i-1]
  if ans > K:
    break
  for j in range(M+1):
    if j == 0:
      ans2 = ans
    else:
      ans2 += B[j-1]
    if ans2 > K:
      break
    else:
      mmax = max(mmax, i+j)

print(mmax)

# 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, 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()))
time = 0
count = 0
if(min(min(A),min(B))>K):
    print((0))
    exit()
while time<=K:
    if(len(A)!=0 and len(B)!=0):
        if(A[0]<B[0]):
            time+= A[0]
            A.pop(0)
            count +=1
        elif(A[0]>B[0]):
            time += B[0]
            B.pop(0)
            count+=1
    elif((len(A)==0) and (len(B)==0)):
        break
    elif(len(A)==0):
        time += B[0]
        B.pop(0)
        count += 1
    elif(len(B)==0):
        time += A[0]
        A.pop(0)
        count += 1
if(time == K):
    print(count)
else:
    print((count-1))

# 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]
A_sum.extend(A)
B_sum.extend(B)
for i in range(1,N+1):
    A_sum[i]+=A_sum[i-1]
for i in range(1,M+1):
    B_sum[i]+=B_sum[i-1]
ans,j=0,M
for i in range(N+1):
    if A_sum[i]>K:
        break
    while B_sum[j]+A_sum[i]>K:
        j-=1
    ans = max(ans,i+j)
print(ans)
# Original solution
n, m, k = list(map(int, input().split()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
for i in range(n+1):
    if AS[i] > k:
        break
    for j in range(0, m+1):
        if AS[i] + BS[j] > k:
            break
        ans = max(ans, i+j)
        
print(ans)


# Optimized solution
n, m, k = list(map(int, input().split()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
from itertools import accumulate
AS = [0] + list(accumulate(A))
BS = [0] + list(accumulate(B))

ans = 0
j = m
for i in range(n+1):
    if AS[i] > k:
        break

    while AS[i] + BS[j] > k:
        j -= 1
    ans = max(ans, i+j)
        
print(ans)
# Original 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]
for i in range(1, M+1):
    B[i] += B[i-1]

ans = 0

for a_index in range(N+1):
    left = K - A[a_index]
    if left < 0: continue

    b_index = M
    while left - B[b_index] < 0:
        b_index -= 1

    ans = max(ans, a_index + b_index)

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]
for i in range(1, M+1):
    B[i] += B[i-1]

ans = 0

b_index = M

for a_index in range(N+1):
    left = K - A[a_index]
    if left < 0: continue

    while left - B[b_index] < 0:
        b_index -= 1

    ans = max(ans, a_index + b_index)

print(ans)
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
from functools import lru_cache

INF = 10**9 + 1

@lru_cache(None)
def get_max(A,B,rest,cur):
    if len(A) > 0:
        a = A[0]
    else:
        a = INF
    if len(B) > 0:
        b = B[0]
    else:
        b = INF
    if rest < a and rest < b:
        return cur

    if rest >= a:
        tmp_a = get_max(tuple(list(A)[1:]),B,rest-a,cur+1)
    else:
        tmp_a = 0
    if rest >= b:
        tmp_b = get_max(A,tuple(list(B)[1:]),rest-b,cur+1)
    else:
        tmp_b = 0

    return max(tmp_a,tmp_b)



def main():
    N,M,K = [int(i) for i in input().strip().split()]
    A = tuple([int(i) for i in input().strip().split()])
    B = tuple([int(i) for i in input().strip().split()])


    ans = get_max(A,B,K,0)

    return ans

if __name__ == "__main__":
    print((main()))

# Optimized solution
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

def main():
    N,M,K = [int(i) for i in input().strip().split()]
    A = [int(i) for i in input().strip().split()]
    B = [int(i) for i in input().strip().split()]

    pre_A = [0] * (N + 1)
    pre_B = [0] * (M + 1)


    for i in range(1,N+1):
        pre_A[i] = pre_A[i-1] + A[i-1]
    for i in range(1,M+1):
        pre_B[i]= pre_B[i-1] + B[i-1]

    ans = 0

    for i in range(N+1):
        for j in range(M+1):
            if pre_A[i] + pre_B[j] <= K:
                ans = max(ans,i+j)
            else:
                break

    return ans

if __name__ == "__main__":
    print((main()))
# Original solution
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

def main():
    N,M,K = [int(i) for i in input().strip().split()]
    A = [int(i) for i in input().strip().split()]
    B = [int(i) for i in input().strip().split()]

    pre_A = [0] * (N + 1)
    pre_B = [0] * (M + 1)


    for i in range(1,N+1):
        pre_A[i] = pre_A[i-1] + A[i-1]
        if pre_A[i] > K:
            idx_a = i-1
            break
    else:
        idx_a = N

    for i in range(1,M+1):
        pre_B[i]= pre_B[i-1] + B[i-1]
        if pre_B[i] > K:
            idx_b = i-1
            break
    else:
        idx_b = M

    ans = max(idx_a,idx_b)

    for i in range(idx_a + 1):
        for j in range(idx_b+1): 
            if pre_A[i] + pre_B[j] <= K:
                ans = max(ans,i+j)
            else:
                break

    return ans

if __name__ == "__main__":
    print((main()))


# Optimized solution
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

def main():
    N,M,K = [int(i) for i in input().strip().split()]
    A = [int(i) for i in input().strip().split()]
    B = [int(i) for i in input().strip().split()]

    pre_A = [0] * (N + 1)
    pre_B = [0] * (M + 1)


    for i in range(1,N+1):
        pre_A[i] = pre_A[i-1] + A[i-1]
        if pre_A[i] > K:
            idx_a = i-1
            break
    else:
        idx_a = N

    for i in range(1,M+1):
        pre_B[i]= pre_B[i-1] + B[i-1]
        if pre_B[i] > K:
            idx_b = i-1
            break
    else:
        idx_b = M

    ans = max(idx_a,idx_b)

    j = idx_b
    for i in range(idx_a + 1):
        while pre_B[j] > K - pre_A[i]:
            j -= 1
        ans = max(ans,i+j)

    return ans

if __name__ == "__main__":
    print((main()))
# Original solution
na,nb,k = list(map(int, input().split()))
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))


def get_bcnt( usek,tb=tb ):
    tb_sum = [ sum(tb[:i]) + tt for i, tt in enumerate(tb)]
    tb_sum_tf = [ i <= usek for i in tb_sum]
    
    if False in tb_sum_tf:
        return tb_sum_tf.index(False)
    else:
        return len(tb)
    
 
readbook = [ i+1 + get_bcnt( k - sum( ta[:i] ) )  for i in range(na) if sum( ta[:i+1] ) <= k ]
readbook.append( get_bcnt(k) )
print(( max(readbook) ))

# Optimized solution
na,nb,k = list(map(int, input().split()))
ta = list(map(int, input().split()))
tb = list(map(int, input().split()))

a = [0]
for i in range(na):
  a.append( a[i] + ta[i] )
b = [0]
for i in range(nb):
  b.append( b[i] + tb[i] )

ans, j=0, nb
for i in range(na + 1):
  if a[i] > k:
    break
  while True:
    if a[i] + b[j] > k:
      j -= 1
    else:
      break
  ans = max(ans, i+j)
    
print(ans)
# Original solution
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque

#input = sys.stdin.readline
#import numpy as n
import bisect



def main():

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

    A = list(map(int,input().split()))
    B = list(map(int, input().split()))
    cumA=[0]*(len(A)+1)
    cumB = [0] * (len(B)+1)
    tempA=0
    for i in range(1,len(A)+1):
        cumA[i]=tempA+A[i-1]
        tempA+= A[i-1]
    tempB = 0
    for i in range(1,len(B)+1):
        cumB[i] = tempB + B[i-1]
        tempB+= B[i-1]
#    print(cumB)
    ans =0
    for i in range(len(A)+1):
        res = K - cumA[i]
        if res<0:
            break
        b_read = bisect.bisect_right(cumB,res)
        ans =max( i + b_read,ans)
 #       print("b_read {}// i {}//ans {}".format(b_read,i,ans))

    print((ans-1))


if __name__ == "__main__":
    main()

# Optimized solution
import sys
#import numpy as np
#from collections import defaultdict
import math
#from collections import deque

#input = sys.stdin.readline
#import numpy as n
import bisect



def main():

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

    A = list(map(int,input().split()))
    B = list(map(int, input().split()))
    cumA=[0]*(len(A)+1)
    cumB = [0] * (len(B)+1)
    tempA=0
    for i in range(1,len(A)+1):
        cumA[i]=tempA+A[i-1]
        tempA+= A[i-1]
    tempB = 0
    for i in range(1,len(B)+1):
        cumB[i] = tempB + B[i-1]
        tempB+= B[i-1]
#    print(cumB)
    ans =0
    j = M
    for i in range(len(A)+1):
        res = K - cumA[i]
        if res<0:
            break
        while cumB[j] + cumA[i] > K:
            j -=1
        ans = max(ans, i + j)
 #       b_read = bisect.bisect_right(cumB,res)
#        ans =max( i + b_read,ans)
 #       print("b_read {}// i {}//ans {}".format(b_read,i,ans))

    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, 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
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
# C - Tsundoku
def calc_cusum(n):
	cusum = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		cusum[i + 1] = cusum[i] + int(arr[i])
	
	return cusum


def identify_position(i, j):
  global a
  global b
  global k
  global m
  
  if a[i] + b[j] > k:
    while j > 0:
      j -= 1
      
      if a[i] + b[j] <= k:
        break
  else:
    while j < m and a[i] + b[j+1]<= k:
      j += 1
  
  return j


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

ans = 0
j = 0

for i in range(n + 1):
  j = identify_position(i, j) 
  
  #print(a[i])
  #print(b[j])
  #print(i + j)
  
  if a[i] + b[j] <= k:
    ans = max(ans, i+j)

print(ans)

# Optimized solution
# C - Tsundoku
def calc_cusum(n):
	cusum = [0] * (n + 1)
	arr = input().split()
	
	for i in range(n):
		cusum[i + 1] = cusum[i] + int(arr[i])
	
	return cusum


def get_max_book(cusum):
  global k
  
  for i in range(len(cusum)):
    if cusum[i] > k:
      return i -1
  
  return len(cusum) - 1


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

ans = 0
j = get_max_book(b)

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

print(ans)
# Original solution
# -*- coding: utf-8 -*-
# 標準入力を取得
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 j in range(M):
    b.append(b[j] + B[j])

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
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    return N, M, K, A, B


def main(N: int, M: int, K: int, A: list, B: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): 机Aの本の数（1 <= N <= 200000）
        M (int): 机Bの本の数（1 <= M <= 200000）
        K (int): 合計所要時間の上限（1 <= K <= 10^9）
        A (list): 机Aの本を読むための時間
        B (list): 机Bの本を読むための時間
    """
    # 求解処理
    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for j in range(M):
        b.append(b[j] + B[j])

    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)


if __name__ == "__main__":
    # 標準入力を取得
    N, M, K, A, B = get_input()

    # メイン処理
    main(N, M, K, A, B)
# Original solution
n, m, k = list(map(int, input().split(' ')))
ans = 0

a_ls = [0] + list(map(int, input().split(' ')))
b_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, n+1):
    a_ls[i] += a_ls[i-1]
for i in range(1, m+1):
    b_ls[i] += b_ls[i-1]

for a_cnt in range(0, n+1):
    if a_ls[a_cnt] > k:
        continue
    b_cnt = m
    while a_ls[a_cnt] + b_ls[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)

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

a_ls = [0] + list(map(int, input().split(' ')))
b_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, n+1):
    a_ls[i] += a_ls[i-1]
for i in range(1, m+1):
    b_ls[i] += b_ls[i-1]

b_cnt = m
for a_cnt in range(0, n+1):
    if a_ls[a_cnt] > k:
        continue
    while a_ls[a_cnt] + b_ls[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)
# Original solution
N, M, K = list(map(int, input().split(' ')))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, N + 1):
    A_ls[i] += A_ls[i - 1]
for i in range(1, M + 1):
    B_ls[i] += B_ls[i - 1]

a_cnt, b_cnt, rst = -1, -1, 0
for i in range(N + 1):
    if A_ls[i] > K:
        break
    for j in range(M + 1):
        if A_ls[i] + B_ls[j] > K:
            break
        rst = max(rst, i + j)
print(rst)

# Optimized solution
N, M, K = list(map(int, input().split(' ')))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

for i in range(1, N + 1):
    A_ls[i] += A_ls[i - 1]
for i in range(1, M + 1):
    B_ls[i] += B_ls[i - 1]

b_cnt, rst = M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)
# Original solution
N, M, K = list(map(int, input().split(' ')))
A_ls = [0] + list(map(int, input().split(' ')))
B_ls = [0] + list(map(int, input().split(' ')))

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

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

a_cnt, b_cnt, rst = 0, M, 0
while a_cnt < N + 1:
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt > 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
    a_cnt += 1
print(rst)

# Optimized solution
N, M, K = list(map(int, input().split(' ')))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] += B_ls[i]

a_cnt, b_cnt, rst = 0, M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K:
        b_cnt -=1
    rst = max(rst, a_cnt + b_cnt)
print(rst)
# Original solution
N, M, K = list(map(int, input().split(' ')))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] += B_ls[i]

a_cnt, b_cnt, rst = 0, M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt > 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
    b_cnt = M
print(rst)

# Optimized solution
N, M, K = list(map(int, input().split(' ')))
A_ls = [0] + list(map(int, input().split(' ')))
for i in range(N):
    A_ls[i + 1] += A_ls[i]
B_ls = [0] + list(map(int, input().split(' ')))
for i in range(M):
    B_ls[i + 1] += B_ls[i]

a_cnt, b_cnt, rst = 0, M, 0
for a_cnt in range(N + 1):
    if A_ls[a_cnt] > K:
        break
    while A_ls[a_cnt] + B_ls[b_cnt] > K and b_cnt > 0:
        b_cnt -= 1
    rst = max(rst, a_cnt + b_cnt)
print(rst)