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

a = [False]*N
b = [False]*M

ans = 0
now = 0
bf = 0

for i in range(N):
    if now + A[i] > K:
        break
    now += A[i]
    ans += 1
    a[i] = True

for i in range(M):
    if now + B[i] > K:
        break
    now += B[i]
    ans += 1
    b[i] = True
    bf = i

if all(a) and all(b):
    print(ans)
    exit()

if not any(a) and not any(b):
    print(ans)
    exit()

n = K - now
ans2 = ans
for i in reversed(list(range(N))):
    if a[i]:
        a[i] = False
        n += A[i]
        ans2 -= 1
        for j in range(bf,M):
            if not b[j]:
                if n - B[j] < 0:
                    break
                b[j] = True
                n -= B[j]
                ans2 += 1
    if ans2 > ans:
        ans = ans2

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 = [False]*N
b = [False]*M

ans = 0
now = 0
bf = 0

for i in range(N):
    if now + A[i] > K:
        break
    now += A[i]
    ans += 1
    a[i] = True

for i in range(M):
    if now + B[i] > K:
        break
    now += B[i]
    ans += 1
    b[i] = True
    bf = i

if all(a) and all(b):
    print(ans)
    exit()

if not any(a) and not any(b):
    print(ans)
    exit()

n = K - now
ans2 = ans
for i in reversed(list(range(N))):
    if a[i]:
        a[i] = False
        n += A[i]
        ans2 -= 1
        for j in range(bf,M):
            if not b[j]:
                if n - B[j] < 0:
                    break
                b[j] = True
                bf = j
                n -= B[j]
                ans2 += 1
    if ans2 > ans:
        ans = ans2

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

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

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

A_length = len(A)
B_length = len(B)

for i in range(A_length):
    j = 0
    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    ans = max(ans, i + (j - 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()))
ans = 0

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

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

A_length = len(A)
B_length = len(B)

j = 0
for i in range(A_length):

    while j < B_length:
        if A[i] + B[j] <= K:
            j += 1
        else:
            break
    j -= 1

    ans = max(ans, A_length - (i + 1) + 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(A[:i+1]) for i in range(n)]
b=[sum(B[:j+1]) for j in range(m)]
i=n-1
j=m-1
x=0
while i>=0:
  if a[i]>k:
    i-=1
    continue
  while j>=0:
    if b[j]<=k-a[i]:
      break
    j-=1
  x=max(x,i+j+2)
  i-=1
print(x)

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

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

ans, j = 0, M
for i in range(N + 1):
 if a[i] > K:
  break
 while b[j] > K - a[i]:
  j -= 1
 ans = max(ans, i + j)
print(ans)
# Original solution
N, M, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

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

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

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

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

cnt = 0
b_idx = M
for i in range(N+1):
    if a[i] > K:
        break
    for j in range(b_idx, -1, -1):
        if a[i] + b[j] <= K:
            cnt = max(cnt, i+j)
            b_idx = j
            break
print(cnt)
# Original solution
import sys
input = sys.stdin.readline

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

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

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

print(res)


# Optimized solution
import sys
input = sys.stdin.readline

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

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

j = m

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

print(res)
# 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

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

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

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]
for i in range(N):
    a.append(a[i]+A[i])
b = [0]
for i in range(M):
    b.append(b[i]+B[i])

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 = 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
# coding: utf-8
# Your code here!
from itertools import accumulate
#import numpy as np

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

sum_A = list(accumulate(A))
sum_B = list(accumulate(B))


#sum_A = np.cumsum(A)
#sum_B = np.cumsum(B)

list_N = [0 for i in range(len(A)+1)]

pre_n = len(B)

for i in range(len(A)+1):
    if i == 0:
        buf = sum_B[:pre_n]
        num_B = sum([1 if buf[j] <= K else 0 for j in range(len(buf))])
        #len(buf[buf<=K])
        pre_n = num_B
        list_N[i] = i + num_B
    else:
        if K>=sum_A[i-1]:
            buf = sum_B[:pre_n]
            num_B = sum([1 if buf[j] <= (K-sum_A[i-1]) else 0 for j in range(len(buf))])
            #len(buf[buf<=(K-sum_A[i-1])])
            pre_n = num_B
            list_N[i] = i + num_B
            #print(K-sum_A[i-1])
            #print(i, num_B)
        else:
            list_N[i] = 0
    
#print(A)
#print(B)
#print(sum_A)
#print(sum_B)
#print(list_N)
print((max(list_N)))

# Optimized solution
# coding: utf-8
# Your code here!
from itertools import accumulate
#import numpy as np

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

sum_A = list(accumulate(A))
sum_B = list(accumulate(B))


#sum_A = np.cumsum(A)
#sum_B = np.cumsum(B)

list_N = [0 for i in range(len(A)+1)]

pre_n = len(B)

for i in range(len(A)+1):
    if i == 0:
        num_B = 0
        for j in range(pre_n)[::-1]:
            if sum_B[j] <= K:
                num_B = j+1
                break
            else:
                continue
        #len(buf[buf<=K])
        pre_n = num_B
        list_N[i] = i + num_B
    else:
        if K>=sum_A[i-1]:
            num_B = 0
            for j in range(pre_n)[::-1]:
                if sum_B[j] <= (K-sum_A[i-1]):
                    num_B = j+1
                    break
                else:
                    continue
            #len(buf[buf<=(K-sum_A[i-1])])
            pre_n = num_B
            list_N[i] = i + num_B
            #print(K-sum_A[i-1])
            #print(i, num_B)
        else:
            list_N[i] = 0
    
#print(A)
#print(B)
#print(sum_A)
#print(sum_B)
#print(list_N)
print((max(list_N)))
# Original solution
N, M, K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SUM_A=[0 for _ in range(N+1)]
for i in range(N):
    SUM_A[i+1] = A[i] + SUM_A[i]
    if SUM_A[i+1] > K:
        N=i
        break

SUM_B=[0 for _ in range(M+1)]
for i in range(M):
    SUM_B[i+1] = B[i] + SUM_B[i]
    if SUM_B[i+1] > K:
        M=i
        break

cnt = N
for i in range(N+1)[::-1]:
    V=K-SUM_A[i]
    j = 0
    while j < M+1 and SUM_B[j] <= V:
        j += 1
    j-=1
    if i+j > cnt:
        cnt = i+j
print(cnt)

# Optimized solution
N, M, K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
SUM_A=[0 for _ in range(N+1)]
for i in range(N):
    SUM_A[i+1] = A[i] + SUM_A[i]
    if SUM_A[i+1] > K:
        N=i
        break

SUM_B=[0 for _ in range(M+1)]
for i in range(M):
    SUM_B[i+1] = B[i] + SUM_B[i]
    if SUM_B[i+1] > K:
        M=i
        break

cnt = N
for i in range(N+1)[::-1]:
    V=K-SUM_A[i]
    j = cnt-i
    while j < M+1 and SUM_B[j] <= V:
        j += 1
    j-=1
    if i+j > cnt:
        cnt = i+j
print(cnt)
# Original solution
import sys
input = sys.stdin.buffer.readline

import bisect
N, M, K = list(map(int, input().split()))
A = list(map(int, (input().split())))
B = list(map(int, (input().split())))
cumA, cumB = [0], [0]
for a in A:
    cumA.append(cumA[-1]+a)
for b in B:
    cumB.append(cumB[-1]+b)
ans = 0
for i in range(N, -1, -1):
    if cumA[i] > K: continue
    j = bisect.bisect_right(cumB, K-cumA[i])
    ans = max(ans, i+j-1)
print(ans)

# Optimized solution
import sys
input = sys.stdin.buffer.readline

N, M, K = list(map(int, input().split()))
A = list(map(int, (input().split())))
B = list(map(int, (input().split())))
t = sum(B)
# 尺取法
j = M   # bはmから減らしていく
ans = 0
for i in range(N+1):    # aは0からnまで増やしていく
    if i: t += A[i-1]   # i個までの累計になるように足す 0個は0
    while (j>0 and t>K):    # t<=k または j==0 で抜ける
        j -= 1
        t -= B[j]
    if t>K: break   # bが0番まで行っても　t>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()))

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 = 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 sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    n,m,k = list(map(int, stdin.readline().rstrip().split()))
    A = list(map(int, stdin.readline().rstrip().split()))
    B = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    Ar = [0]
    for i in range(n):
        Ar.append(Ar[i] + A[i])
    Br = [0]
    for i in range(m):
        Br.append(Br[i] + B[i])
    ans = 0
    end = m
    for i in range(n+1):
        flag = 0
        time_a = Ar[i]
        for j in range(m):
            while end >= 0:
                if Br[end] + time_a > k:
                    end -= 1
                else:
                    ans = max(ans, i+end)
                    flag = 1
                    break
            if flag == 1:
                flag = 0
                break

    print(ans)


if __name__ == '__main__':
    solve()


# Optimized solution
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    #n = int(stdin.readline().rstrip())
    N,M,K = list(map(int, stdin.readline().rstrip().split()))
    A = list(map(int, stdin.readline().rstrip().split()))
    B = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    a = [0]
    for i in range(N):
        a.append(a[i] + A[i])
    b = [0]
    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)


if __name__ == '__main__':
    solve()
# Original solution
import bisect
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0

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

for j in range(n+1):
  K=k-A[j]
  if K<0:
    break
  else:
    ans=max(ans,bisect.bisect_right(B,K)+j-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()))
ans,right=0,0

A,B=[0],[0]
for i in range(n):
  A.append(a[i]+A[i])
for i in range(m):
  B.append(b[i]+B[i])
for i in range(m+1):
  if k<B[i] or i==m:
    right=i-1
    if i==m:
      right=i
    ans=right
    break

for j in range(0,n):
  if k<a[j]:
    break
  k-=a[j]
  while k<B[right]:
    right-=1
  ans=max(ans,right+j+1)
print(ans)
# Original solution
from bisect import bisect
from collections import deque

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

csumA = [0]
csumB = [0]

s = 0
for i in A:
    s += i
    csumA.append(s)
s = 0
for i in B:
    s += i
    csumB.append(s)

ans = 0
for i in range(N+1):
    if K - csumA[i] >= 0:
        ##print(i,i+bisect(csumB,max(0,K-csumA[i])))
        ans = max(ans,i-1+bisect(csumB,max(0,K-csumA[i])))

for i in range(M+1):
    if K - csumB[i] >= 0:
        ans = max(ans,i-1+bisect(csumA,max(0,K-csumB[i])))

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
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]
bb=[0]
a_sum=0
b_sum=0

for i in range(n):
    if (a_sum+a[i])<=k:
        a_sum+=a[i]
        aa.append(a_sum)
    else:
        break
for i in range(m):
    if (b_sum+b[i])<=k:
        b_sum+=b[i]
        bb.append(b_sum)
    else:
        break

#print(aa)
#print(bb)
cnt=0
for i in range(len(aa)):
    for j in range(len(bb)):
        if (aa[i]+bb[j])<=k:
            cnt=max(cnt,i+j)
print(cnt)


# Optimized solution
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
aa=[0]
bb=[0]
a_sum=0
b_sum=0

for i in range(n):
    if (a_sum+a[i])<=k:
        a_sum+=a[i]
        aa.append(a_sum)
    else:
        break
for i in range(m):
    if (b_sum+b[i])<=k:
        b_sum+=b[i]
        bb.append(b_sum)
    else:
        break

#print(aa)
#print(bb)
cnt=len(bb)-1
ans=0
for i in range(len(aa)):
    for j in range(cnt,-1,-1):
        if bb[j]<=(k-aa[i]):
            cnt=j
            ans=max(ans,(i+j))
            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=[0]
B=[0]
ans=0
j=M
for i in range(N):
  A.append(A[i]+a[i])
for i in range(M):
  B.append(B[i]+b[i])
for i in range(N+1):
  if A[i]>K:
    break
  while A[i]+B[j]>K:
    j-=1
  ans=max(ans,i+j)
print(ans)


# Optimized solution
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
n,m,k=MI()
a=[0]+LI()
b=[0]+LI()
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
j=m
for i in range(n+1):
  if a[i]>k:
    continue
  while a[i]+b[j]>k:
    j-=1
  ans=max(ans,i+j)
print(ans)
# Original solution
N, N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ruisekiA = [0]
ruisekiB = [0]
tmpA=0
tmpB=0
for i in range(len(A)):
    tmpA += A[i]
    ruisekiA.append(tmpA)
for i in range(len(B)):
    tmpB += B[i]
    ruisekiB.append(tmpB)
ans = 0
for i in range(len(ruisekiA)):
    #tmp = ruisekiA[i]
    l = -1
    r = len(ruisekiB)
    while r - l > 1:
        mid = (r + l)//2
        tmp = ruisekiA[i]+ruisekiB[mid]
        if tmp <= K:
            l = mid
        else:
            r = mid
    if l == -1:
        continue
    ans = max(ans, i+l)
print(ans)

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

ruisekiA = [0]
ruisekiB = [0]
tmpA=0
tmpB=0
for i in range(len(A)):
    tmpA += A[i]
    ruisekiA.append(tmpA)
for i in range(len(B)):
    tmpB += B[i]
    ruisekiB.append(tmpB)
ans = 0
for i in range(len(ruisekiA)):
    #tmp = ruisekiA[i]
    l = 0
    r = len(ruisekiB)
    if ruisekiA[i] > K:
        continue
    while r - l > 1:
        mid = (r + l)//2
        tmp = ruisekiA[i]+ruisekiB[mid]
        if tmp <= K:
            l = mid
        else:
            r = mid

    ans = max(ans, i+l)
print(ans)
# Original solution
n, m, k =list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ta=sum(a)
a.append(0)
tb=0
ans=0

for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    for j in range(m):
        tb += b[j]
        if tb + ta >k:
            break
        if j==m-1:
            j +=1

    ans=max(ans,n-i+j)
    tb=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()))
ta=sum(a)
a.append(0)
tb=0
ans=0
j=0
for i in range(n+1):
    ta -= a[n-i]
    if ta>k:
        continue
    while tb + ta<=k:

        if j ==m:
            ans=max(ans,n-i+j)
            break
        ans=max(ans,n-i+j)
        tb += b[j]
        j +=1

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

lia = [0]
lib = [0]
tmp = M
ans = 0

for i in range(N):
    lia.append(lia[i]+A[i])
for i in range(M):
    lib.append(lib[i]+B[i])

for i in range(N+1):
    kari = 0
    t = K - lia[i]
    kari += i

    if t<0:
        break
    elif t==0:
        ans = max(ans, i)
        break
    else:
        pass

    for j in range(tmp,-1,-1):
        if t<lib[j]:
            continue
        else:
            tmp = j
            kari += j
            ans = max(ans, kari)
            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()))

lia = [0]
lib = [0]
j = M
ans = 0

for i in range(N):
    lia.append(lia[i]+A[i])
for i in range(M):
    lib.append(lib[i]+B[i])

for i in range(N+1):
    if lia[i] > K:
        break

    while lib[j] > K-lia[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)
# Original solution
from bisect import *
n, m, k = list(map(int, input().split()))
A = [0]
for x in map(int, input().split()):
    if A[-1]+x > k: break
    A.append(A[-1]+x)
B = [0]
for x in map(int, input().split()):
    if B[-1]+x > k: break
    B.append(B[-1]+x)
ans = 0
for i in range(len(A)):
    j = bisect_right(B, k-A[i]) - 1
    ans = max(ans, i+j)
print(ans)


# Optimized solution
from bisect import *
n, m, k = list(map(int, input().split()))
A = [0]
for x in map(int, input().split()):
    x += A[-1]
    if x > k: break
    A.append(x)
B = [0]
for x in map(int, input().split()):
    x += B[-1]
    if x > k: break
    B.append(x)
ans = 0
for i in range(len(A)):
    ans = max(ans, i + (bisect_right(B, k-A[i]) - 1))
print(ans)
# Original solution
from bisect import *
n, m, k = list(map(int, input().split()))
A = [0]
for x in map(int, input().split()):
    x += A[-1]
    if x > k: break
    A.append(x)
B = [0]
for x in map(int, input().split()):
    x += B[-1]
    if x > k: break
    B.append(x)
ans = 0
for i in range(len(A)):
    ans = max(ans, i + (bisect_right(B, k-A[i]) - 1))
print(ans)


# Optimized solution
from bisect import *
n, m, k = list(map(int, input().split()))
A, B = [0], [0]
for x in map(int, input().split()): A.append(A[-1]+x)
for x in map(int, input().split()): B.append(B[-1]+x)
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
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sum_A = [0]
for i,a in enumerate(A, 1):
    sum_A.append(sum_A[i-1] + a)
    
sum_B = [0]
for i,b in enumerate(B, 1):
    sum_B.append(sum_B[i-1] + b)
    
ans = 0
    
for i in range(N+1):
    for j in range(M, -1, -1):
        if sum_A[i] + sum_B[j] > K:
            pass
        else:
            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()))

sum_A = [0]
for i,a in enumerate(A, 1):
    tmp = sum_A[i-1] + a
    if tmp <= K:
        sum_A.append(tmp)
        mark_A = i
    else:
        break
    
sum_B = [0]
for i,b in enumerate(B, 1):
    tmp = sum_B[i-1] + b
    if tmp <= K:
        sum_B.append(tmp)
        mark_B = i
    else:
        break
    
ans = 0
j = len(sum_B) - 1

for i,a in enumerate(sum_A):
    while sum_B[j] > K - a:
        j -= 1
        
    ans = max(ans, i+j)
    
print(ans)