Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

def main():
    N, W = (int(i) for i in input().split())
    weight = [0] * (N+1)
    value = [0] * (N+1)
    for i in range(1, N+1):
        w, v = (int(i) for i in input().split())
        weight[i] = w
        value[i] = v
    memo = [[-1 for i in range(W + 1)] for j in range(N + 1)]

    def rec(i, w):
        if i == 0:
            return 0
        if memo[i][w] != -1:
            return memo[i][w]
        res = 0
        if w - weight[i] >= 0:
            res = max(rec(i-1, w), rec(i-1, w-weight[i])+value[i])
        else:
            res = rec(i-1, w)
        memo[i][w] = res
        return res

    print(rec(N, W))


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, W = (int(i) for i in input().split())
    weight = [0] * (N+1)
    value = [0] * (N+1)
    for i in range(1, N+1):
        w, v = (int(i) for i in input().split())
        weight[i] = w
        value[i] = v
    dp = [[0 for i in range(W + 1)] for j in range(N + 1)]

    for i in range(1, N+1):
        for w in range(W+1):
            if w - weight[i] >= 0:
                dp[i][w] = max(dp[i-1][w], dp[i-1][w - weight[i]] + value[i])
            else:
                dp[i][w] = dp[i-1][w]

    print(dp[N][W])


if __name__ == '__main__':
    main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-

N = int(input())
A = [int(input()) for x in range(N)]
ans = max(A)
for i in range(N):
    if A[i] == ans:
        print(max(A[:i] + A[i+1:]))
    else:
        print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-

N = int(input())
A = [int(input()) for x in range(N)]
max1, max2 = sorted(A, reverse=True)[:2]
for i in range(N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)
### BUGGY CODE ###

n=int(input())
ab=[list(map(int,input().split()))]
b=[ab[0]]
answer=1
for i in range(n-1):
    k=list(map(int,input().split()))#kを今からbの値でソートします
    d=0#何番目に入れるのが最適化を探すための代数です。
    while  d<=i and k[1]<=ab[d][1]:
        d+=1
    ab.insert(d,k) 
    b.insert(d,k)
#print(ab)
#print(b)
k=0
for t in range(n):
    k+=ab[n-1-t][0]
    #print([k,answer])
    if k>ab[n-1-t][1]:
        answer=answer*0
if answer==1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n=int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
#print(ab)
k=0
answer=1
for t in range(n):
    k+=ab[t][0]
    #print([k,answer])
    if k>ab[t][1]:
        answer=answer*0
if answer==1:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
maxA = max(A)

nums = [0]*(maxA+2)
A.sort()
cnt = 0 
ans = defaultdict(int)
for a in A:
    # print('nums', nums)
    new = False
    if nums[a]==0:
        # print(a)
        cnt += 1
        ans[a] += 1
        new = True
    mlt = a
    nums[a] += 1
    while new and a + mlt < maxA+2:
        a += mlt
        # print(' a:', a)
        nums[a] += 1

for an in ans.keys():
    if A.count(an)>1:
        cnt -= 1
print(cnt)

### FIXED CODE ###

#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
S = set(A)

maxA = A[-1]
chk = [0] * (maxA+1)
for s in S:
    for i in range(s, maxA+1, s):
        chk[i] += 1

res = [s for s in S if chk[s] == 1 and C[s] == 1]
# print(res)
print(len(res))
### BUGGY CODE ###

N = int(input())
A = map(int, input().split())
result = 1
for i in A:
  result *= i
if result > 10**18:
  print(-1)
else:
  print(result)

### FIXED CODE ###

N = int(input())
A = input().split(" ")
result = 1
if "0" in A:
  print(0)
  exit()
else:
  for i in range(N):
    result *= int(A[i])
    if result > 10**18:
      print(-1)
      exit()
print(result)
### BUGGY CODE ###

A, B, M = map(int, input().split())
lenzi=list(map(int,input().split()))
zouko=list(map(int,input().split()))
mPrice = 200000
for i in range(A):
  for j in range(B):
    if lenzi[i]+zouko[j]<mPrice:
      mPrice=lenzi[i]+zouko[j]
for i in range(M):
  x, y, c = map(int, input().split())
  if lenzi[x-1]+zouko[y-1]-c<mPrice:
    mPrice=lenzi[x-1]+zouko[y-1]-c
print(mPrice)

### FIXED CODE ###

A, B, M = map(int, input().split())
lenzi=list(map(int,input().split()))
zouko=list(map(int,input().split()))
mlenzi=100000
mzouko=100000
mPrice = 200000
for i in range(A):
  if lenzi[i]<mlenzi:
    for j in range(B):
      if zouko[j]<mzouko:
        if lenzi[i]+zouko[j]<mPrice:
          mPrice=lenzi[i]+zouko[j]
        mzouko=zouko[j]
    mlenzi=lenzi[i]
for i in range(M):
  x, y, c = map(int, input().split())
  if lenzi[x-1]+zouko[y-1]-c<mPrice:
    mPrice=lenzi[x-1]+zouko[y-1]-c
print(mPrice)
### BUGGY CODE ###

S = input()
# print("Q=")
Q = int(input())

def problem_gksn(S,Q):
  for _ in range(Q):
    # print("queryを入力してください")
    query = input().split()
    # print("query= ",query)
    if len(query) == 1: #1の場合
      # print("文字を反転させます")
      S = S[::-1]
    else: #2の場合
      # print("文字をくっつけます")
      if int(query[1]) == 2:
        S = S + query[2]
      else:
        S = query[2] + S
  
  return S
print(problem_gksn(S,Q))

### FIXED CODE ###

# print("S=")
S = input()
# print("Q=")
Q = int(input())

def problem_gksn(S,Q):
  check_reverse = 0 # 偶数のとき正常, 奇数の時反転
  atama = ""
  oshiri = ""
  for _ in range(Q):
    # print("queryを入力してください")
    query = input().split()
    # print("query= ",query)
    if len(query) == 1: #1の場合
      # print("文字を反転させます")
      check_reverse += 1
      # S = S[::-1]
    else: #2の場合
      # print("文字をくっつけます")
      if int(query[1]) == 2 - check_reverse % 2:
        oshiri += query[2]
      else:
        atama += query[2]
      # print("atama",atama)
      # print("oshiri",oshiri)
  S = atama[::-1] + S + oshiri
  if check_reverse % 2==1:
    S = S[::-1]
  
  return S

print(problem_gksn(S,Q))
### BUGGY CODE ###

N,W = map(int,input().split())

w = [-1 for i in range(N)]
v = [-1 for i in range(N)]

for i in range(N):
    w[i],v[i] = map(int,input().split())
    
dp = [[0 for i in range(W+1)] for j in range(N)]

#荷物を1つだけ入れた状態で、各許容重量の最大値を初期値として持たせる
for i in range(w[0],W+1):
    dp[0][i] = v[0]

for i in range(1,N):
    for j in range(W+1):
        #
        if j < w[i]:
            dp[i][j] = dp[i-1][j]
        #比較 詰めた一個前/詰めてちょうど/
        else:
            dp[i][j] = max(dp[i][j-1],dp[i-1][j],dp[i-1][j-w[i]]+v[i])


print(dp[N-1][W])

### FIXED CODE ###

from itertools import accumulate

def chk(samp):
    for i in samp:
        print(samp)

N,W = map(int,input().split())

w = [0 for i in range(N)]
v = [0 for i in range(N)]

for i in range(N):
    w[i],v[i]=map(int,input().split())



#価値毎に置き換える
wl = [[] for i in range(4)]

#価値ごとのりすとに入れていく
for i in range(N):
    wl[w[i]-w[0]].append(v[i])


#ソートして最初に0を追加する。0は選択しない場合
for i in range(4):
    wl[i].sort(reverse = 1)
    wl[i].insert(0,0)
    

#累積和を作る
for i in range(4):
    wl[i] = list(accumulate(wl[i]))
    
#出力用変数
out = 0


for i,wl0 in enumerate(wl[0]):
   for j,wl1 in enumerate(wl[1]):
       for k,wl2 in enumerate(wl[2]):
           for l,wl3 in enumerate(wl[3]):
               if i*(w[0])+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3) > W:
                   pass
               else:
                   out = max(out,wl0+wl1+wl2+wl3)
                   
print(out)
### BUGGY CODE ###

A,B,C,K = map(int,input().split())
A_p = 0
B_p = 0
C_p = 0

for i in range(A+1):
  if i > K:
    break
  A_p = i
  
K -= A_p

for i in range(B+1):
  if i > K:
    break
  B_p = i

K -= B_p

for i in range(C+1):
  if i > K:
    break
  C_p = i

K -= C_p
  
print(A_p*1 + C_p*(-1))

### FIXED CODE ###

A,B,C,K = map(int,input().split())

if A >= K:
  print(K*1)
else:
  K -= A
  if B >= K:
    print(A*1)
  else:
    K -= B
    print(A*1 + K*(-1))
### BUGGY CODE ###

import math

N = int(input())
 
mi = 10**10
 
for a in range(int(math.sqrt(N)), N+1, 1):
  if N % a == 0:
    b = N//a
    if mi > a+b-2:
      mi = a+b-2
print(mi)

### FIXED CODE ###

import math

N = int(input())
 
mi = 10**100

for a in range(1, int(math.sqrt(N))+1, 1):
  if N % a == 0:  
    b = N//a
    if mi > a+b-2:
      mi = a+b -2
print(mi)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()

for i in range(Q):
  l, r = map(int, input().split())
  print(S[l-1:r:].count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
  
ac_sum = [0]*N
for i in range(N):
  if S[max(i-1,0):i+1] == "AC":
    ac_sum[i] = ac_sum[max(i-1,0)] + 1
  else:
    ac_sum[i] = ac_sum[max(i-1,0)]

for _ in range(Q):
  l, r = map(int, input().split())
  print(ac_sum[r-1] - ac_sum[l-1])
### BUGGY CODE ###

s=input()
si=len(s)//2+1
ns0=len(s)
ssum=0
for i in range(si):
    nsi=len(s)
    s=s.replace("01","")
    s=s.replace("10","")
    if nsi==len(s):
        break
print(ns0-nsi)

### FIXED CODE ###

s=input()
nall=len(s)
nzero=s.count("0")
none=nall-nzero
if nall==0:
    print(0)
elif none<=nzero:
    print(none*2)
else:
    print(nzero*2)
### BUGGY CODE ###

import fractions
from functools import reduce
def main():
  _=input()
  a=tuple(map(int,input().split()))
  fgcd=fractions.gcd
  def lcm_base(x, y):
    return (x * y) // fgcd(x, y)
  def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
  q=lcm(a)
  x=[q//i for i in a]
  print(sum(x)%(10**9+7))
  
if __name__ == '__main__':
    main()

### FIXED CODE ###

import fractions
from functools import reduce
def main():
  _=input()
  a=tuple(map(int,input().split()))
  fgcd=fractions.gcd
  def lcm_base(x, y):
    return (x * y) // fgcd(x, y)
  def lcm(numbers):
    return reduce(lcm_base, numbers, 1)
  q=lcm(a)
  x=[q//i for i in a]
  print(sum(x)%(10**9+7))
  
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
import collections

As = [collections.deque()]
for i in range(N):
    deq = collections.deque()
    for a in map(int, input().split()):
        deq.append(a)
    As.append(deq)

d = 1
ms = 0
msMax = N * (N - 1) // 2
sw = True
while sw:
    tab = set()
    c = 0
    for i in range(1, N + 1):
        if len(As[i]) == 0:
            continue
        a, b = min(i, As[i][0]), max(i, As[i][0])
        if (a, b) in tab:
            ms += 1
            c += 1
            if ms == msMax:
                sw = False
                break
            As[a].popleft()
            As[b].popleft()
        else:
            tab.add((a, b))
    if c == 0:
        d = 0
        break
    d += 1
print(d - 1)


### FIXED CODE ###

import sys

input = sys.stdin.readline
N = int(input())
As = [list(map(int, input().split())) + [-1] for _ in range(N)]

import collections

que = collections.deque([i for i in range(N)])
counters = [0] * N
days = [0] * N
while que:
    player = que.popleft()
    opponent = As[player][counters[player]] - 1
    if As[opponent][counters[opponent]] - 1 == player:
        days[player] = max(days[player], days[opponent]) + 1
        days[opponent] = days[player]
        counters[player] += 1
        counters[opponent] += 1
        que.append(player)
        que.append(opponent)
for c in counters:
    if c < N - 1:
        print(-1)
        break
else:
    print(max(days))
### BUGGY CODE ###

N,K,Q=map(int,input().split())
arr=[K]*N

for i in range(Q):
    a=int(input())
    for j in range(N):
        if a-1!=j:
            arr[j]-=1
for i in arr:
    if i>0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N,K,Q=map(int,input().split())
arr=[K-Q]*N

for i in range(Q):
    a=int(input())
    arr[a-1]+=1

for i in arr:
    if i>0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

# 全部非再帰に書き換え・numbaなし

import numpy as np

def eular_tour(G, root):
    # G は破壊的に有向木にされる
    # グラフは 1-indexed が良い
    n = len(G)
    stack = [root]
    tour = [0] * 0
    firsts = np.full(n, -100, dtype=np.int64)
    lasts = np.full(n, -100, dtype=np.int64)
    parents = np.full(n, -100, dtype=np.int64)
    while stack:
        v = stack.pop()
        if firsts[v] >= 0:
            lasts[v] = len(tour)
            tour.append(-v)  # 帰りがけの辺の表現をマイナス以外にしたい場合ここを変える
            continue
        firsts[v] = len(tour)
        tour.append(v)
        stack.append(v)
        for u in G[v]:
            G[u].remove(v)
            parents[u] = v
            stack.append(u)
    tour = np.array(tour, dtype=np.int64)
    return tour, firsts, lasts, parents

def solve(N, C, AB):
    G = [[0]*0 for _ in range(N+1)]
    for i in range(N-1):
        a, b = AB[i]
        G[a].append(b)
        G[b].append(a)
    tour, firsts, lasts, parents = eular_tour(G, 1)
    Siz = lasts - firsts + 1 >> 1

    Cnt = np.zeros(N+1, dtype=np.int64)
    Ans = np.zeros(N+1, dtype=np.int64)
    Cnt_old = np.empty_like(Cnt)
    Siz_tmp = np.full_like(Cnt, 1)
    for v in tour:
        if v >= 0:
            p = parents[v]
            if p != -100:
                Cnt[C[p]] = N - Siz[v]  # 上を塞ぐ

            color = C[v]
            Cnt_old[v] = Cnt[color]
        else:
            v = -v
            Ans[C[v]] += N - Siz_tmp[v] + 1 - Cnt_old[v]
            Cnt[C[v]] = Cnt_old[v] + Siz_tmp[v]

            p = parents[v]
            if p != -100:
                Siz_tmp[p] += Siz[v]
                Ans[C[p]] += Siz[v] * (N - Siz_tmp[p] + 1 - Cnt_old[p])

    return Ans[1:]


#numba_compile([
#    [eular_tour, "Tuple((i8[:],i8[:],i8[:],i8[:]))(List(List(i8)),i8)"],
#    [solve, "i8[:](i8,i8[:],i8[:,:])"],
#])


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = np.array(["0"] + input().split(), dtype=np.int64)
AB = np.array([list(map(int, input().split())) for _ in range(N-1)], dtype=np.int64)
Ans = solve(N, C, AB)
print("\n".join(map(str, Ans)))


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(505050)
N = int(input())
C = [int(c)-1 for c in input().split()]
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

Cnt = [0] * N
Ans = [0] * N
Siz = [0] * N

def dfs1(v):
    siz = 1
    for u in G[v]:
        G[u].remove(v)
        siz += dfs1(u)
    Siz[v] = siz
    return siz

#Cnt_down = [0] * N

def dfs(v):
    color = C[v]
    cnt_old = Cnt[color]
    siz = 1
    siz_up = N
    #cnt_down = 0
    for u in G[v]:
        #Cnt_down[color] = 0
        Cnt[color] = N - Siz[u]  # 上を塞ぐ
        s = dfs(u)
        siz += s
        siz_up -= s
        Ans[color] += s * (siz_up-cnt_old)
        #cnt_down += Cnt_down[color]
    Ans[color] += siz_up - cnt_old
    #print(siz_up, cnt_old, cnt_down)
    Cnt[color] = cnt_old + siz
    #print(v, Ans)
    return siz

dfs1(0)
dfs(0)
print("\n".join(map(str, Ans)))
### BUGGY CODE ###

s = input()
dp = [[0 for i in range(2019)] for i in range(len(s)+1)]
mod = 2019
ans = 0
for i in range(len(s)):
    dp[i+1][int(s[i])] += 1
    for j in range(2019):
        dp[i+1][(10 * j + int(s[i])) % 2019] += dp[i][j]
for i in range(1, len(s)+1):
    ans += dp[i][0]
print(ans)

### FIXED CODE ###

s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)
### BUGGY CODE ###

n=int(input())
a=[]
cnt=1
for i in range(n):
	a.append(input())
for i in range(0,n):
	for j in range(i+1,n):
		if a[i]==a[j]:
			break
		elif j == n-1:
			cnt+=1
print(cnt)

### FIXED CODE ###

n=int(input())
a=list(input() for i in range(n))
print(len(set(a)))
### BUGGY CODE ###

N=int(input())
a_list=[int(i) for i in input().split()]

ans=1
for i in range(N):
    ans*=a_list[i]
    
if ans>10**18:
    print(-1)
else:
    print(ans)
    

### FIXED CODE ###

N=int(input())
a_list=[int(i) for i in input().split()]

if 0 in a_list:
    print(0)
    
else:
    
    ans=1
    for i in range(N):
        ans*=a_list[i]
        if ans>10**18:
            ans=-1
            break
    print(ans)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = []
B = []
for _ in range(N):
    s = input().split()
    A.append(int(s[0]))
    B.append(int(s[1]))

def set_list(es):
    return np.unique(es).shape[0] == 1

ind = 0

A = np.array(A)
B = np.array(B)

a_happy = 0
b_happy = 0
A_flag = 0
B_flag = 0

if set_list(A):
    A_flag = 1

if set_list(B):
    B_flag = 1

for i in range(N):
    if i%2 == 0:
        if A_flag == 0:
            ind =np.argmax(A)
            a_happy += A[ind]
            A = np.delete(A, ind)
            B = np.delete(B, ind)
            if set_list(B):
                B_flag = 1
        elif A_flag == 1:
            ind =np.argmax(B)
            a_happy += A[ind]
            A = np.delete(A, ind)
            B = np.delete(B, ind)
    if i%2 == 1:
        if B_flag == 0:
            ind =np.argmax(B)
            b_happy += B[ind]
            A = np.delete(A, ind)
            B = np.delete(B, ind)
            if set_list(A):
                A_flag = 1
        elif B_flag == 1:
            ind =np.argmax(A)
            b_happy += B[ind]
            A = np.delete(A, ind)
            B = np.delete(B, ind)

print(a_happy - b_happy)


### FIXED CODE ###

import numpy as np

N = int(input())
C = []
for _ in range(N):
    a, b = map(int, input().split())
    C.append([a+b, a, b])

D = sorted(C, reverse=True)

ans = 0

for i in range(N):
    if i % 2 == 0:
        ans += D[i][1]
    elif i % 2 == 1:
        ans -= D[i][2]

print(ans)
### BUGGY CODE ###

X, Y, Z, K = [int(i) for i in input().split()]
ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)]

ABSum = sorted([i + j for i in ABCList[0] for j in ABCList[1]], reverse=True)[:K]
for ans in sorted([i + j for i in ABSum for j in ABCList[2]], reverse=True)[:K]:
    print(ans)


### FIXED CODE ###

X, Y, Z, K = [int(i) for i in input().split()]
ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)]

ansList = []
for i, A in enumerate(ABCList[0]):
    for j, B in enumerate(ABCList[1]):
        for k, C in enumerate(ABCList[2]):
            if (i + 1) * (j + 1) * (k + 1) <= K:
                ansList.append(A + B + C)
            else:
                break

for ans in sorted(ansList, reverse=True)[:K]:
    print(ans)
### BUGGY CODE ###

# F
import numpy as np
from collections import deque

TT_list = []
# input
N, L = map(int, input().split())
T = 0.0
que = deque()

for i in range(N):
    ti, v = map(int, input().split())
    t = float(ti)
    if v == L:
        que.append([t, v])
    else:
        while v < L and len(que) > 0:
            t_, v_ = que.pop()
            if t_ <= t:
                que.append([t_, v_])
                que.append([t, v])
                break
            elif v + v_ > L:
                v_ = v + v_ - L
                t = ((L - v) * t_ + v * t) / L
                v = L
                que = deque([[t, v]])
                # break
            else:
                t = (t*v + t_*v_) / (v + v_)
                v = v + v_
    VV = 0
    TT = 0
    for i in range(len(que)-1, -1, -1):
        t, v = que[i]
        if VV + v >= L:
            TT = ((L - VV) * t + VV * TT) / L
            VV = L
            break
        else:
            TT = (t*v + TT*VV) / (v + VV)
            VV += v
            
            
    TT_list.append(TT)

for i in range(N):
    print(TT_list[i])

### FIXED CODE ###

# F
from collections import deque
 
TT_list = []
# input
N, L = map(int, input().split())
T = 0.0
vt_now = 0.0
v_now = 0
que = deque()

for i in range(N):
    ti, v = map(int, input().split())
    t = float(ti)
    v_now += v
    vt_now += v*t
    # add
    if v == L:
        que.append([t, v])
    else:
        while v < L and len(que) > 0:
            t_, v_ = que[-1]
            if t_ <= t:
                que.append([t, v])
                break
            elif v + v_ >= L:
                v_ = v + v_ - L
                t = ((L - v) * t_ + v * t) / L
                v = L
                que = deque([[t, v]])
                v_now = L
                vt_now = t*L
                # break
            else:
                t = (t*v + t_*v_) / (v + v_)
                v = v + v_
                que.pop()
    # minus
    while v_now > L:
        if que[0][1] <= v_now - L:
            v_now -= que[0][1]
            vt_now -= que[0][1]*que[0][0]
            que.popleft()
        else:
            que[0][1] -= v_now - L
            vt_now -= (v_now - L)*que[0][0]
            v_now = L
            
    TT_list.append(vt_now / L)

for i in range(N):
    print(TT_list[i])
### BUGGY CODE ###

N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
AA = [0]
BB = [0]
r = 0
for i in A:
    r += i
    AA.append(r)
r = 0
for i in B:
    r += i
    BB.append(r)
ans = 0
for i,v in enumerate(AA):
    for j,w in enumerate(BB):
        x = i+j
        y = v+w
        if y > K:
            break
        if x > ans:
            ans = x
print(ans)



### FIXED CODE ###

N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
AA = [0]
BB = [0]
r = 0
for i in A:
    r += i
    AA.append(r)
r = 0
for i in B:
    r += i
    BB.append(r)
ans = 0
a = N
b = 0
while AA[a]+BB[b] > K:
    a -= 1
ans = a+b

while a >= 0:
    while b < M:
        if AA[a]+BB[b+1] <= K:
            b += 1
        else:
            break
    if ans < a+b:
        ans = a+b
    if b == M:
        break
    a -= 1
print(ans)