peterverebics/CodeNet_Python_118 huggingface dataset:
# -*- coding: utf-8 -*-
m, n, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.extend(B)
del B
AB = sorted(A)
s=0
l=0
for i in AB:
    if s+i <= k:
        s+=i
        l+=1
    else:
        break
print("{}".format(l))
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ab = a + b
ab.sort()
ans = 0
now = k
for elem in ab:
    now -= elem
    if now < 0:
        break
    ans += 1
print(ans)
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

# cumsum
a_sum = [0] * n
a_sum[0] = a[0]
for i in range(1, n):
    a_sum[i] = a_sum[i-1] + a[i]

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

ans = 0
for i in range(n):
    a_total = a_sum[i]
    if a_total > k: break
    j = bisect.bisect_right(b_sum, k - a_total)
    ans = max(ans, i + j + 1)
print(ans)
n, m, k = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

A.append(float('inf'))
B.append(float('inf'))

sum,min,ans,i,j = 0,0,0,0,0

while True:
    if A[i] < B[j]:
        min = A[i]
        i += 1
    else:
        min = B[j]
        j += 1
    
    if sum + min > k: 
        break
    else:
        sum += min
        ans += 1

print(ans)
from bisect import bisect
from itertools import accumulate
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    book = list(accumulate(sorted(A + B)))
    ans = bisect(book, K)
    print(ans)


main()
from collections import deque

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

ans = 0
cnt = 0
while True:
    if a: at = a.popleft()
    if b: bt = b.popleft()
    if at < bt:
        cnt += at
        b.appendleft(bt)
    else:
        cnt += bt
        a.appendleft(at)
    if cnt >= k:
        print(ans)
        exit()
    ans += 1
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
ai=0
bi=0
loopcnt=len(a)+len(b)
for i in range(loopcnt):
  ans+=1
  if len(a)-ai==0:
    k-=b[bi]
    bi+=1
  elif len(b)-bi==0:
    k-=a[ai]
    ai+=1
  elif a[ai]>b[bi]:
    k-=b[bi]
    bi+=1
  else:
    k-=a[ai]
    ai+=1
  if k<0:
    ans-=1
    break
print(ans)
N ,M ,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
result = 0

A.append(1000000001)
B.append(1000000001)
i,j = 0,0
for k in range(N+M):
    if A[i] <= B[j]:
        K -= A[i]
        i += 1
    else:
        K -= B[j]
        j += 1
    if K < 0:
        break
    result += 1
print(result)
import bisect

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acum = [A[0]] + [0]*(n-1)
Bcum = [B[0]] + [0]*(m-1)
for i in range(1,n):
    Acum[i] = Acum[i-1] + A[i]
for i in range(1,m):
    Bcum[i] = Bcum[i-1] + B[i]
maxn = 0
for i in range(m):
    if Bcum[i] < k:
        maxn = max(maxn,i + 1 + bisect.bisect_right(Acum, k-Bcum[i]))

print(maxn)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
count=0
while c+min(a[0],b[0])<=k:
  
 c+=min(a[0],b[0])
 count+=1
 if min(a[0],b[0])==a[0]:
   a.remove(a[0])
   if not a:
        a.append(1000000000)
 else:
   b.remove(b[0]) 
   if not b:
        b.append(1000000000)
print(count)
N, M, KK = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

max = N
if N < M:
  max = M
sum = 0

for i in range(max):
  k = 0
  if len(a) > 0:
    k = a[0]
  if len(b) > 0 and k > b[0]:
    k = b[0]
  
  if KK - k > 0:
    sum += 1
    KK -= k
print(sum)
def aaa():
    n,m,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = []
    for i,j in zip(a,b):
        c.append(i)
        c.append(j)
    c = sorted(c)
    d = 0
    e = 0
    for i in c:
        if i+e < k:
            e += i
            d += 1
        else:
            return d
    return n + m
nnn = aaa()
print(nnn)
from collections import deque

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

count = 0
for i in range(N + M):
  if len(A) == 0:
    book = B.popleft()
  elif len(B) == 0:
    book = A.popleft()
  else:
    if A[0] < B[0]:
      book = A.popleft()
    else:
      book = B.popleft()
  
  if K >= book:
    count += 1
    K -= book
  else:
    break

print(count)
n,m,k=map(int,input().split())
A=[0]+list(map(int,input().split()))
B=[0]+list(map(int,input().split()))
from itertools import accumulate
from bisect import bisect_right
A=list(accumulate(A))
B=list(accumulate(B))
ans=0
t=0
for a in range(n+1):
    t=k-A[a]
    b=bisect_right(B,t)-1
    if B[b]>k:continue
    ans=max(ans,a+b)
print(ans)
import sys
sys.setrecursionlimit(10**6)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A.append(99999)
B.append(99999)
Sum = 0
i = 0
j = 0
while True:
  if A[i] <= B[j] and Sum + A[i] <= K:
    Sum += A[i]
    i += 1
  elif A[i] > B[j] and Sum + B[j] <= K:
    Sum += B[j]
    j += 1
  else:
    break
if Sum >= 1000000000:
  print(0)
else:
  print(i + j)
n,m,k=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])
  if AS[-1]>k:
    break
for i in B:
  BS.append(i+BS[-1])
  if BS[-1]>k:
    break
f=1
for i in range(1,len(AS)):
  for j in range(f,len(BS)):
    if AS[-i]+BS[-j]<=k:
      if len(AS)+len(BS)-i-j>r:
        r=len(AS)+len(BS)-i-j
      f=j
print(r)
import bisect

N, M, K = map(int, input().split())
Alist = [0] + list(map(int, input().split()))
Blist = list(map(int, input().split()))

B = [Blist[0]]
for b in Blist[1:]:
    B.append(b + B[-1])


sums = 0
ans = 0
for idx, a in enumerate(Alist):
    sums += a
    if sums > K:
        break
    k = K - sums
    print(k)
    tmp = bisect.bisect_right(B, k)
    ans = max(ans, idx + tmp)

print(ans)
N, M, K = 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)
N, M, K = map(int,input().split())
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))
AL.extend(BL)
AAL = sorted(AL)

if sum(AAL) <= K:
    print(len(AAL))
    exit()

cnt = 0
ans = 0
for i in range(N+M):
    cnt += AAL[i]
    ans += 1
    if cnt >= K:
        print(ans-1)
        exit()
n,m,k = map(int,input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ac = 0
bc = 0
ans = 0
t = 0

while t<k:
  if bc<=m-1 and ac <=n-1:
    if a[ac] > b[bc]:
      t += b[bc]
      bc +=1
      ans+=1
    else:
      t+= a[ac]
      ac+=1
      ans+=1
  elif ac >= n and bc<=m-1:
    t += b[bc]
    bc +=1
    ans+=1
  elif bc >= m and ac<=n-1:
    t+= a[ac]
    ac+=1

if t>k:
  ans -=1

print(ans)
import collections as cs

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

A.append(K + 1)
B.append(K + 1)

count = -1
time = 0

while time <= K:
    count += 1
    if A[0] <= B[0]:
        time += A.popleft()
    else:
        time += B.popleft()

print(count)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
c = 0
ans = -1
ia = 0
ib = 0
while c <= K:
  if ia == N and ib == M:
    ans += 1
    break
  elif ia == N:
    c += B[ib]
    ib += 1
     
  elif ib == M:
    c += A[ia]
    ia += 1
    
  elif A[ia] <= B[ib]:
    c += A[ia]
    ia += 1
     
  else:
    c += B[ib]
    ib += 1
    
  ans += 1
print(ans)
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
i = 0
while x < K:
  if(As != [] and Bs != []):
    if(As[0] >= Bs[0]):
      x += Bs.pop(0)
      i += 1
    elif(As[0] < Bs[0]):
      x += As.pop(0)
      i += 1
  elif(As == [] and Bs == []):
    print(i - 1)
  elif(Bs == []):
    x += As.pop(0)
    i += 1
  elif(As == []):
    x += Bs.pop(0)
    i += 1
print(i - 1)
from collections import deque
n,m,k=map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A,B = deque(A),deque(B)
time,ans = 0,0
while A or B:
  if not A: v = B.popleft()
  elif not B: v = A.popleft()
  elif A[0] <= B[0]: v = A.popleft()
  else: v = B.popleft()
  if time + v > k: break
  time += v
  ans += 1
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
count = 0
while K > 0:
    if A == []:
        K -= B.pop(0)
    elif B == []:
        K -= A.pop(0)
    else:
        if A[0] >= B[0]:
            K -= B.pop(0)
        else:
            K -= A.pop(0)
    if K >= 0:
        count += 1
print(count)
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
i = 0
j = 0
time = 0
ans = 0
for _ in range(n+m+1):
  if A[i] < B[j] and  i != n-1:
    ans +=1
    time += A[i]
    i += 1
  else:
    if j != m-1:
      ans +=1
      time += B[j]
      j += 1
  
  if time > k:
    ans -= 1
    print(ans)
    exit()
  
  if (i+1)+(j+1) == n+m:
    print(n+m)
    exit()
def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    c = a + b
    c.sort()
    sum = 0
    for i in range(len(c)):
        sum += c[i]
        if k < sum:
            return print(i)
    print(len(c))


main()
n, m, k = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
aa = a.copy()
bb = b.copy()

aa = [sum(a[:s+1]) for s in range(n)]
bb = [sum(b[:s+1]) for s in range(m)]
      
temp, ans = 0, 0

for i in range(1, n):
    for j in range(m)[::-1]:
        if aa[i] + bb[j] <= k:
            temp = i+1 + j+1
            break
    if temp > ans:
        ans = temp
        
print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))


maxNum = 0
cnt = 0


for i in a:
    if k - i > 0:
        k -= i
        cnt += 1
    else:
        break

    for j in b:
        if k - j > 0:
            k -= j
            cnt += 1
        else:
            break
    
    maxNum = max(maxNum, cnt)


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

time = 0
count = -1
while time <= K:
    count += 1
    if len(A) == 0 and len(B) == 0:
        break
    elif len(A) == 0:
        time += B.pop(0)

    elif len(B) == 0:
        time += A.pop(0)

    else:
        if A[0] <= B[0]:
            time += A.pop(0)

        else:
            time += B.pop(0)
print(count)
import sys
a, b, n = map(int, input().split())
alis = list(map(int, input().split()))
blis = list(map(int, input().split()))
alis.append(sys.maxsize)
blis.append(sys.maxsize)

count = 0
time = 0

ac = 0
bc = 0
while time <= n:
    time += min(alis[ac], blis[bc])
    count += 1
    if alis[ac] <= blis[bc]:
        ac += 1
    else:
        bc +=1

print(count-1)
from bisect import bisect

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

csumA = []
csumB = []

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):
    if K - csumA[i] >= 0:
        ans = max(ans,i+1+bisect(csumB,max(0,K-csumA[i])))

print(ans)
N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
cost = 0
ans = 0
pa = 0
pb = 0
while cost <= K:
	if pa < N and pb < M:
		if A[pa] <= B[pb]:
			cost += A[pa]
			pa += 1
		else:
			cost += B[pb]
			pb += 1
		ans += 1
	elif pa < N:
		cost += A[pa]
		pa += 1
		ans += 1
	elif pb < M:
		cost += B[pb]
		pb += 1
		ans += 1
	else:
		ans += 1
		break;
print(ans-1)
N, M, K = 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(len(A)) if sum(A[:i+1]) <= K]
B_ = [sum(B[:i+1]) for i in range(len(B)) if sum(B[:i+1]) <= K]

x = [i+j+2 for i in range(len(A_)) for j in range(len(B_)) if A_[i]+B_[j] <= K]
print(max(x) if len(x) > 0 else 0)
from collections import deque
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ad = deque(a)
ad.append(float('inf'))
bd = deque(b)
bd.append(float('inf'))
count = 0
while True:
    k = k - min(ad[0],bd[0])
    if k < 0 or ad[0] == float('inf') and bd[0] == float('inf'):
        break
    if ad[0] > bd[0]:
        bd.popleft()
    else:
        ad.popleft()
    count += 1
print(count)
import bisect
 
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
 
a_sum = [0]*(n+1)
b_sum = [0]*(m+1)
 
for i in range(n):
  a_sum[i+1] =  a_sum[i] + a[i+1]
for j in range(m):
  b_sum[j+1] =  b_sum[j] + b[j+1]
 
ans = 0
for i in range(n+1):
  j = bisect.bisect_left(b_sum, k - a_sum[i])
  tmp = i + j
  ans = max(ans, tmp)
 
print(ans)
import bisect
N,M,K = map(int,input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
A = [0]
B = [0]
ans = 0
for i in range(N):
  if A[i]+a[i] <=K:
    A.append(A[i]+a[i])
  else:
    break

for i in range(M):
  if B[i]+b[i] <=K:
    B.append(B[i]+b[i])
  else:
    break

if len(A)==1 and len(B)==1:
  print(0)
  exit()
for i in range(len(A)):
  j = bisect.bisect(B,K-A[i]-0.1)
  if ans <i+j:
    ans=i+j
    #print(i,j)
print(ans)
from itertools import accumulate
import sys
import bisect
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=max(len(a),len(b))
if len(a)==c:
    b+=[0]*(c-len(b))
else:
    a+=[0]*(c-len(a))
l=[]
for A,B in zip(a,b):
    l.append(min(A,B))
    l.append(max(A,B))
cumsum=list(accumulate(l))
print(bisect.bisect_left(cumsum,k))
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()]
a.append(int(1e10))
b.append(int(1e10))

books = 0
i = 0
j = 0
while True:
    if min(a[i], b[j]) > k: 
        break
    if a[i] <= b[j]:
        k -= a[i]
        books += 1
        i += 1
    else:
        k -= b[j]
        books += 1
        j += 1
print(books)
import bisect
N,M,K=map(int,input().split())
SumA=[0]*(N+1)
SumB=[0]*(M+1)
A=list(map(int, input().split()))
B=list(map(int,input().split()))
for i in range(1,N+1):
    SumA[i]= A[i-1]+SumA[i-1]
for i in range(1,M+1):
    SumB[i] = B[i-1]+SumB[i-1]

ans = 0
for i in range(N+1):
    num = i
    rest = K-SumA[i]
    if rest<=0:
        break;
    num += bisect.bisect_right(SumB, rest)-1
    ans = max(num, ans)

print(ans)
import sys
sys.setrecursionlimit(10 ** 9)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
def dfs(a, b, t):
    global cnt
    cnt = max(cnt, a+b)
    if a < N and t + A[a] <= K:
        dfs(a+1, b, t+A[a])
    if b < M and t + B[b] <= K:
        dfs(b+1, a, t+B[b])
    
dfs(0, 0, 0)
print(cnt)
import bisect

n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acum = [A[0]] + [0]*(n-1)
Bcum = [B[0]] + [0]*(m-1)
for i in range(1,n):
    Acum[i] = Acum[i-1] + A[i]
for i in range(1,m):
    Bcum[i] = Bcum[i-1] + B[i]
maxn = 0
for i in range(m):
    if Bcum[i] < k:
        maxn = max(maxn,i + 1 + bisect.bisect_left(Acum, k-Bcum[i]))

print(maxn)
n, m, k = map(int, input().strip().split())

a = list(map(int, input().strip().split()))[:n]
b = list(map(int, input().strip().split()))[:m]
  
all = []
all.extend(a)
all.extend(b)
print(*all)
counter = 0
am = 0
if(k - min(all) >= 0):
  while(k > 0):
    print(k)
    am = min(all)
    k-= am
    counter += 1
    all.remove(am)
    if(len(all) == 0):
        break
else:
  counter = 0
  
  
print(counter)
[N,M,K]=list(map(int, input().split()))
alist=list(map(int, input().split()))
blist=list(map(int, input().split()))
clist=alist+blist
clist.sort()

time=0
ans=-1
ci=0
while time<=K :
    ans+=1

    #print(time,ans)
    if ans == len(clist):
        break
    time+=clist[ans]


print(ans)
import bisect
N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
A_cumulative_sum = [A[0]]
B_cumulative_sum = [B[0]]
for i in range(1, N):
    A_cumulative_sum.append(A[i] + A[i - 1])
for i in range(1, M):
    B_cumulative_sum.append(B[i] + B[i - 1])

for i in range(N):
    if K < A_cumulative_sum[i]:
        break
    remaining_time = K - A_cumulative_sum[i]
    idx = bisect.bisect_right(B_cumulative_sum, remaining_time)
    ans = max(ans, i + 1 + idx)
print(ans)
n,m,k=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])
a.pop(0)
b.pop(0)
j=m-1
x=0
for i in range(n-1,-1,-1):
  if a[i]>k:
    continue
  while j>=0 and b[j]>k-a[i]:
    j-=1
  x=max(x,i+j+2)
print(x)
# coding: utf-8
import math
import bisect
N, M, K = map(int,input().split())
#N = int(input())
#K = int(input())
#S = input()
ans = 0
flg = True
#l = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

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

na = bisect.bisect_right(A, K)
#print(na)
for i in range(na-1):
    time_b = K-A[i]
    nb = bisect.bisect_right(B, time_b)
    ans = max(ans, i+nb+2)
print(ans)
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(len(a))]
b = [sum(b[:i+1]) for i in range(len(b))]
ans = 0
for i in range(n):
    for j in reversed(range(m)):
        if a[i]+b[j]<=k:
            ans = max(ans, i+j+2)
            m=j+1
            break
print(ans)
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
time = 0
cnt = 0
while time <= K:
  if len(A) == 0 and len(B) == 0:
    break
  if len(A) == 0:
    tmp = B.pop(0)
  elif len(B) == 0:
    tmp = A.pop(0)
  elif A[0]<B[0]:
    tmp = A.pop(0)
  else:
    tmp = B.pop(0)
  time += tmp
  if time > K:
    break
  cnt += 1
 # print(time,A,B)
print(cnt)
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list()
D=list()
c=0
d=0
for i in range(n):
    c+=A[i]
    C.append(k-c)
for i in range(m):
    D.append(d+B[i])
    d+=B[i]
ans=0
#C=[i for i in C if i>=0]
for i in range(n):
    now=C[i]
    s=0
    while D[s]<=now:
        s+=1
        if s>=len(D):
            break
    if s>0:
        ans=max(ans,i+s+1)
print(ans)
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = A+B
C.sort()
ans = 0
for c in C:
  if c <= k:
    ans += 1
    k -= c
print(ans)
n,m,k=map(int,input().split())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))

sumA=sum(arr)
bpointer=0
ans=0
sumB=0
for i in range(len(arr),-1,-1):
    if i<n:
        sumA-=arr[i]
    if sumA<=k:
        while bpointer<m and sumA+sumB+brr[bpointer]<=k:
            sumB+=brr[bpointer]
            bpointer+=1
    ans=max(ans,i+bpointer)
print(ans)
import sys
input = sys.stdin.readline

n, m, k = map(int, input().split())
a, b, c = list(map(int, input().split())), list(map(int, input().split())), 0
ga, gb, x = True, True, 0
while 1:
    if len(a) == 0: ga = False
    if len(b) == 0: gb = False
    if not ga and not gb: break
    if not ga: x = b.pop(0)
    if not gb: x = a.pop(0)
    if ga and gb:
        if a[0] < b[0]: x = a.pop(0)
        else: x = b.pop(0)
    if k - x < 0: break
    k -= x; c += 1
print(c)
from collections import deque

(n, m, k), aa, bb = [deque(map(int, l.split())) for l in open(0)]

ans = 0

while 1:
    nx = k

    if len(aa):
        nx = min(nx, aa[0])

    if len(bb):
        nx = min(nx, bb[0])

    if len(aa) and aa[0] == nx:
        k-=aa.popleft()
        ans += 1
        
    elif len(bb) and bb[0] == nx:
        k-=bb.popleft()
        ans += 1
        
    else:
        break

print(ans)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
alls = a + b
alls.sort()
count = 0

for i in alls:
  if i<=k:
    count+=1
    k=k-i
print(count)
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

while True:
    a_ = a[0] if len(a) else 10 ** 9 + 1
    b_ = b[0] if len(b) else 10 ** 9 + 1
    
    if min(a_, b_) > 10**9 or min(a_, b_) > k:
        break
    
    if a_ <= b_:
        k -= a.pop(0)
        ans += 1
    else:
        k -= b.pop(0)
        ans += 1
print(ans)
from sys import stdin
input = stdin.readline

N, M, K = 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]

ans = 0
k = M - 1

for i in range(N):
    for j in range(k, -1, -1):
        if K < A[i] + B[j]:
            k -= 1
            continue
        else:
            ans = max(ans, i + j + 2)
            break

print(ans)
N, M, K = map(int, input().split())
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
x = 0
y = 0
i = 0
min = 0
for x in range(N):
  min += As[x]
  i += 1
  if(min > K):
    break
  for y in range(M):
    min += Bs[y]
    i += 1
    if(min > K):
      break
print(i)
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
sum_list = []
for i in range(N):
  for j in range(M):
    sum_ = sum(A[:i+1]) + sum(B[:j+1])
    if sum_ <= K:
      sum_list.append(len(A[:i+1]) + len(B[:j+1]))
    elif K < sum_:
      break
if 1 <= len(sum_list):
  print(max(sum_list))
elif 0 == len(sum_list):
  print(0)
import bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
sa,sb = [0],[0]
ans = 0
for i in range(n):
    sa.append(sa[i]+a[i])
for i in range(m):
    sb.append(sb[i]+b[i])


for i in range(n+1):
    sai = sa[i]
    x = k-sai
    if x>0:
        ans = max(ans,bisect.bisect_right(sb,x)-1+i)
print(ans)
n , m , k = map( int , input().split() )

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

list = a + b
list = sorted(list)

l = n + m

m = 0
count = 0

for i in range(l):
    if count + list[i] <= k:
        count += list[i]
        m += 1
        print(count)
print(m)
n, m, k =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)
import numpy as np

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

sumA = np.cumsum(A)
sumB = np.cumsum(B)
#print(sumA)
#print(sumB)
ans=0

for i in range(n+1):
    ab=sumA[i]+sumB
    s=sum(ab<=k)
    if s-1>0:
        x=i+s-1
        if x>ans:
            ans=x
print(ans)
N, M, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())

sum_A = [0, A[0]]
sum_B = [0, B[0]]

for a in A[1:]:
  sum_A.append(sum_A[-1] + a)

for b in B[1:]:
  sum_B.append(sum_B[-1] + b)

ans = 0
for i in range(N+1):
  for j in range(M, 0, -1):
    if sum_A[i] + sum_B[j] <= K:
      ans = max(ans, i+j)
      break

print(ans)