CodeEff/ECCO huggingface dataset:
# Original solution
N, T = list(map(int, input().split()))
c = [0]*N
t = [0]*N
for i in range(N):
    c[i], t[i] = list(map(int, input().split()))
min_cost = 1001
for i in range(N):
    if t[i]<=T:
        min_cost = min(c[i],min_cost)
if min_cost == 1001:
    print("TLE")
else:
    print(min_cost)

# Optimized solution
N,T = list(map(int, input().split()))
c = [0]*N
t = [0]*N
cost = 1001
for i in range(N):
    c[i], t[i] = list(map(int,input().split()))
    if t[i]<=T:
        cost  = min(cost,c[i])
if cost == 1001:
    print("TLE")
else:
    print(cost)
# Original solution
n,t,*l=list(map(int,open(0).read().split()))
c=3e9
for i,j in zip(l[::2],l[1::2]):
	if j<=t:
		c=min(c,i)
print((c*(c<3e9)or"TLE"))

# Optimized solution
N,T,*L=list(map(int,open(0).read().split()))
print((min([1111]+[c for c,t in zip(*[iter(L)]*2)if t<=T])%1111or"TLE"))
# Original solution
import itertools
import math
import fractions
import functools
import copy

N, T = list(map(int, input().split()))
c= []
t = []
for i in range(N):
     ci, ti = list(map(int, input().split()))
     c.append(ci)
     t.append(ti)

cost = 10**10
for i in range(N):
    if t[i] <= T:
        cost = min(cost,c[i])
if cost == 10**10:
    print("TLE")
else:print(cost)

# Optimized solution
def main():
    # n = int(input())
    n, t = list(map(int, input().split()))
    # a = list(map(int, input().split()))
    # s = input()
    ct = []
    for _ in range(n):
        ct.append(list(map(int, input().split())))

    mini = 10**10
    for i in range(n):
        if ct[i][1] <= t and ct[i][0] < mini:
            mini = ct[i][0]

    if mini == 10**10:
        print("TLE")
    else:
        print(mini)


if __name__ == '__main__':
    main()
# Original solution
import math

N, T = list(map(int, input().split()))

c_list = []
for i in range(N):
    c1, t1=[int(i) for i in input().split()]
    if t1 <= T:
        c_list.append(c1)

if not c_list:
    print('TLE')
else:
    print((min(c_list)))


# Optimized solution
n, T = list(map(int, input().split()))
ans = 1003
for _ in range(n):
    c, t = list(map(int, input().split()))
    if t <= T:
        ans = min(ans, c)

print(('TLE' if ans == 1003 else ans))
# Original solution
N, T = list(map(int, input().split()))

ans = float('inf')

for i in range(N):
    c, t = list(map(int, input().split()))
    if t <= T:
        if c <= ans:
            ans = c
            
if ans == float('inf'):
    print('TLE')
else:
    print(ans)

# Optimized solution
N, T = list(map(int, input().split()))

ans = float('inf')

for i in range(N):
    c, t = list(map(int, input().split()))
    if t <= T:
        ans = min(ans, c)
            
if ans == float('inf'):
    print('TLE')
else:
    print(ans)
# Original solution
N, T = list(map(int, input().split()))
C = []
for _ in range(N):
	c, t = list(map(int, input().split()))
	if t <= T:
		C.append(c)
if C == []:
	print("TLE")
else:
	print((min(C)))


# Optimized solution
N, T = list(map(int, input().split()))
ct = [list(map(int, input().split())) for _ in range(N)]
cti = [i for i in ct if i[1] <= T]

if len(cti) == 0:
    print("TLE")
else:
    print((min(cti)[0]))
# Original solution
N, T = list(map(int, input().split()))

ct = []

for i in range(N):
    ct.append([int(i) for i in input().split()])

ct.sort(key=lambda x: x[0])

ans = 1001

for i in range(N):
    if ct[i][1] <= T:
        ans = ct[i][0]
        break

print(("TLE" if ans == 1001 else ans))


# Optimized solution
N, T = list(map(int, input().split()))

ct = [[int(j) for j in input().split()] for i in range(N)]

ct.sort(key=lambda x: x[0])

ans = 1001

for i in range(N):
    if ct[i][1] <= T:
        ans = ct[i][0]
        break

print(("TLE" if ans == 1001 else ans))
# Original solution
n,t=list(map(int,input().split()))
xList=[]

for i in range(n):
    x,y=list(map(int,input().split()))
    if y<=t:
        xList.append(x)
if len(xList)==0:
    print('TLE')
    exit()

minn=xList[0]
for i in xList:
    if i<minn:
        minn=i

print (minn)


# Optimized solution
N,T=input().split()
aaaaaaaaaaaaaaaaaaaaaa=0
b=0
for i in range(int(N)):
    c,t=input().split()
    if int(t)<=int(T):
        if b==0:
            aaaaaaaaaaaaaaaaaaaaaa=c
            b+=1
        if int(c)<int (aaaaaaaaaaaaaaaaaaaaaa):
            aaaaaaaaaaaaaaaaaaaaaa=c
            i+=1
if aaaaaaaaaaaaaaaaaaaaaa==0:
    print("TLE")
else :
    print(aaaaaaaaaaaaaaaaaaaaaa)
# Original solution
N,T = (input().split())
N = int(N)
T = int(T)
roads = []
for i in range(N) :
    c , t = input().split()
    t = int(t)
    if t in range (1, T + 1):
        roads.append((int(c) ,t))

if len(roads) == 0 :
    print ("TLE")
else:
    roads.sort()
    print((roads[0][0]))

# Optimized solution
N, T=list(map(int, input().split()))

'''aux=[input().split() for _ in range(N)]
aux.sort()'''

c, aux=[], []
for i in range(N):
	x, y=list(map(int, input().split()))
	
	if(y<=T):
		aux=[[int(x), int(y)]]	
		c.extend(aux)
			

if (len(c)==0):
	print("TLE")
else:
	aux=min(c)
	print((aux[0]))
# Original solution
n, T = list(map(int, input().split()))
ct = [list(map(int, input().split())) for _ in range(n)]

ans = []
for i in ct:
    if i[1] <= T:
        ans.append(i[0])
if len(ans) == 0:
    print('TLE')
else:
    print((min(ans)))

# Optimized solution
n, T = list(map(int, input().split()))
ct = [list(map(int, input().split())) for _ in range(n)]
li = []
for i in ct:
    if i[1] <= T:
        li.append(i[0])
if len(li) != 0:
    print((min(sorted(li))))
else:
    print('TLE')
# Original solution
def ans():
  N, T = list(map(int,input().split()))
  cost = 1e9
  for _ in range(N):
    c, t = list(map(int,input().split()))
    if(t <= T):
      if(cost > c):
        cost = c
  if(cost == 1e9):
    print("TLE")
  else:
    print(cost)
ans()

# Optimized solution
N, T = list(map(int,input().split()))
ans = 1e9
for i in range(N):
  c, t = list(map(int,input().split()))
  if(t <= T):
    ans = min(ans, c)
if(ans == 1e9):
  ans = "TLE"
print(ans)
# Original solution
n,t = list(map(int,input().split()))
minc = 10000
for i in range(n):
    ci,ti = list(map(int,input().split()))
    if ti<=t:
        minc = min(minc,ci)
if minc == 10000:
    print("TLE")
else:
    print(minc)

# Optimized solution
ans = 10000
n,t = list(map(int,input().split()))
for i in range(n):
    ci,ti = list(map(int,input().split()))
    if ti <= t:
        ans = min(ans,ci)
if ans == 10000:
    ans = "TLE"

print(ans)
# Original solution
N, T = list(map(int, input().split()))

c = []
t = []
for _ in range(N):
    _c, _t = list(map(int, input().split()))

    if _t <= T:
        c.append(_c)
        t.append(_t)

if len(c) == 0:
    print('TLE')
else:
    print((min(c)))
    

# Optimized solution
N, T = list(map(int, input().split()))

min_c = 1001

for _ in range(N):
    _c, _t = list(map(int, input().split()))

    if _t <= T:
        min_c = min(min_c, _c)

if min_c == 1001:
    print('TLE')
else:
    print(min_c)
# Original solution
# https://beta.atcoder.jp/contests/abc112/tasks/abc112_b

def solve():
    cost = 1001
    N, time = list(map(int, input().split()))
    for _ in range(N):
        c, t = list(map(int, input().split()))
        if t <= time:
            if c <= cost:
                cost = c

    if cost == 1001:
        print('TLE')
    else:
        print(cost)


if __name__ == '__main__':
    solve()


# Optimized solution
def solve():
    cost = 1001
    N, time = list(map(int, input().split()))
    for _ in range(N):
        c, t = list(map(int, input().split()))
        if t <= time and c <= cost:
            cost = c
    print(('TLE' if cost is 1001 else cost))


if __name__ == '__main__':
    solve()
# Original solution
n,t=input().split()
n,t=int(n),int(t)

c=1001
for i in range(n):
    ck,tk=input().split()
    if int(tk)<=t and int(ck)<c:
        c=int(ck)
        
if c==1001:
    print("TLE")
else:
    print(c)


# Optimized solution
n,t=list(map(int,input().split()))
ct=[list(map(int,input().split())) for i in range(n)]
c=10000000000000000
for i in range(n):
    if ct[i][1]<=t:
        c=min(c,ct[i][0])
print((c if c!=10000000000000000 else "TLE"))
# Original solution
def main():
    N , M, K = list(map(int, input().split()))
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    book = 0
    re = M

    for i in range(N+1) :
        if al[i] > K :
            break
        #for j in range(M+1) :
        #    if bl[re] <= K - al[i] :
        #        break
        #    else :
        #        re -= 1
        while bl[re] > K - al[i] :
            re -= 1

        book = max(book, i + re)

    print(book)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N , M, K = list(map(int, input().split()))
    A_list = list(map(int, input().split()))
    B_list = list(map(int, input().split()))

    al = [0]
    bl = [0]

    for i in range(N) :
        al.append(al[i] + A_list[i])
    for i in range(M) :
        bl.append(bl[i] + B_list[i])
    #print("al = %s" % al)
    #print("bl = %s" % bl)
    book = 0
    re = M

    for i in range(N+1) :
        if al[i] > K :
            break
        for j in bl :
            if bl[re] <= K - al[i] :
                break
            else :
                re -= 1
        #while bl[re] > K - al[i] :
        #    re -= 1

        book = max(book, i + re)

    print(book)


if __name__ == '__main__':
    main()
# Original solution
A, B, time = input().split(" ")

a = input().split(" ")
Desk_A = a[:int(A)]
b = input().split(" ")
Desk_B = b[:int(B)]

count = 0
time_f = 0
FLAG = True
FLAG2 = True
i = 0

while time_f < int(time):
    if i < len(Desk_A) and time_f + int(Desk_A[i]) <= int(time):
        time_f = time_f + int(Desk_A[i])
        Desk_A.remove(Desk_A[i])
        count += 1
    else:
        FLAG = False
        if time_f >= int(time):
            break

    if i < len(Desk_B) and time_f + int(Desk_B[i]) <= int(time):
        time_f = time_f + int(Desk_B[i])
        Desk_B.remove(Desk_B[i])
        count += 1

    else:
        FLAG2 = False
        if time_f >= int(time):
            break

    if FLAG is False and FLAG2 is False:
        break


print(count)


# 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])
 
#print(a)
#print(b)
 
ans=0
j=M
for i in range(N+1):
    if a[i]>K:
        break
    while b[j]>K-a[i]:
        j-=1
    #print(i,j)
    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()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
pointer=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m+1 and bsum[bpointer]+asum[i]<=k:
    bpointer+=1
    if bpointer==m+1:
      break
  bpointer-=1
  ans=max(ans,i+bpointer)
print(ans)

# Optimized solution
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
asum=[0]
bsum=[0]
current=0
for i in range(n):
  current+=a[i]
  asum.append(current)
current=0
for i in range(m):
  current+=b[i]
  bsum.append(current)
pointer=0
for i in range(n+1):
  if asum[i]>k:
    pointer=i-1
    break
  if i==n:
    pointer=n
ans=pointer
bpointer=0
for i in range(pointer,-1,-1):
  while bpointer<m and bsum[bpointer+1]+asum[i]<=k:
    bpointer+=1
  ans=max(ans,i+bpointer)
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
asum=0
bsum=0
for j in range(m):
	bsum+=b[j]
	if asum+bsum<=k:
		ans=max(ans,(j+1))
for i in range(n):
	asum+=a[i]
	bsum=0
	if asum+bsum<=k:
		ans=max(ans,(i+1))
	for j in range(m):
		bsum+=b[j]
		if asum+bsum<=k:
			ans=max(ans,(i+1)+(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
asum=0
bsum=0
pointer=0
while pointer<m and bsum+b[pointer]<=k:
	bsum+=b[pointer]
	pointer+=1
ans=pointer
for i in range(n):
	asum+=a[i]
	while asum+bsum>k and pointer>=0:
		pointer-=1
		bsum-=b[pointer]
	if asum+bsum>k:
		break
	ans=max(ans,(i+1)+pointer)
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] * (n + 1)
b = [0] * (m + 1)

for i in range(1, n + 1):
    a[i] = A[i - 1] + a[i - 1]

for j in range(1, m + 1):
    b[j] = B[j - 1] + b[j - 1]

ans = 0

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

for i in range(1, n + 1):
    a[i] = A[i - 1] + a[i - 1]

for j in range(1, m + 1):
    b[j] = B[j - 1] + b[j - 1]

ans = 0
num_b = m

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

print(ans)
# Original solution
import sys
sys.setrecursionlimit(10**9)

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

    a.insert(0, 0)
    b.insert(0, 0)

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

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

    ans = 0
    for i_a in range(n+1):
        for j_b in range(m+1):
            if a_sum[i_a]+b_sum[j_b] <= k:
                ans = max(ans, i_a + j_b)
            else:
                break

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)

# Optimized solution
import sys
sys.setrecursionlimit(10**9)

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

    a.insert(0, 0)
    b.insert(0, 0)

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

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

    b_sum = b_sum[::-1]

    i_b = 0
    ans = 0
    for i_a in range(n+1):
        while i_b <= m:
            if k < a_sum[i_a] + b_sum[i_b]:
                i_b += 1
                continue
            else:
                ans = max(ans, i_a+(m-i_b))
                break

    print(ans)
    return


if __name__ == "__main__":
    main()
    sys.exit(0)
# Original solution
from bisect import bisect_right

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

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

ans = 0
for i in range(N + 1):
    res = K - x[i]
    if res > 0:
        j = bisect_right(y, res)
        j -= 1
    elif res == 0:
        j = 0
    else:
        continue

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

x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
    x[i + 1] = x[i] + A[i]

for i in range(M):
    y[i + 1] = y[i] + B[i]

j = M
ans = 0
for i in range(N + 1):
    if x[i] > K:
        continue
    while j >= 0 and x[i] + y[j] > K:
        j -= 1
    ans = max(ans, i + j)
print(ans)
# Original solution
N,M,K = list(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)



# Optimized solution
N,M,K = list(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)
# Original solution
# coding: utf-8

from bisect import bisect_left


def leq_search(xs, x, s, t):
    # x以下で最大のindex
    if t-s <= 5:
        res = 0
        for i in range(s, t):
            if xs[i] <= x:
                res = i
        return res

    return max(leq_search(xs, x, s, (s+t)//2), leq_search(xs, x, (s+t)//2, t))



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

    S = [None] * (N+1)
    S[0] = 0
    for i in range(1, N+1):
        S[i] = S[i-1] + A[i-1]

    T = [None] * (M+1)
    T[0] = 0
    for i in range(1, M+1):
        T[i] = T[i-1] + B[i-1]

    n_read = 0
    for i in range(N+1):
        # print(i)
        if S[i] > K:
            break
        n = leq_search(T, K-S[i], 0, M+1)
        # print(n, T, K-S[i])
        if n_read < n + i:
            n_read = n + i
    
    return n_read


print((main()))


# Optimized solution
# coding: utf-8

from bisect import bisect_left


def leq_search(xs, x, s, t):
    # x以下で最大のindex
    if t-s <= 5:
        res = 0
        for i in range(s, t):
            if xs[i] <= x:
                res = i
        return res

    i = (s+t)//2
    if xs[i] <= x:
        return leq_search(xs, x, i, t)
    else:
        return leq_search(xs, x, s, i)


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

    S = [None] * (N+1)
    S[0] = 0
    for i in range(1, N+1):
        S[i] = S[i-1] + A[i-1]

    T = [None] * (M+1)
    T[0] = 0
    for i in range(1, M+1):
        T[i] = T[i-1] + B[i-1]

    n_read = 0
    for i in range(N+1):
        # print(i)
        if S[i] > K:
            break
        n = leq_search(T, K-S[i], 0, M+1)
        # print(n, T, K-S[i])
        if n_read < n + i:
            n_read = n + i
    
    return n_read


print((main()))
# Original solution
### 解答


#入力はじめ

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

#入力終わり


#累積和とる

A_wa = [0]
for i in range(N) :
    A_wa.append(A_wa[i]+A[i])

B_wa = [0]
for i in range(M) :
    B_wa.append(B_wa[i]+B[i])

#累積和計算おわり


ans = 0
for i in range(M+1):#Bを順番に増やしていくよー
    A_use = K-B_wa[i]
    if A_use<0: #Bだけでこえてる
        break
    
    ##Aは最大で何冊よめるかな
    A_MAX = 0
    start = 0
    end = N
    while  end-start>=1 : #調べるのが2個以上
        now = int((start + end+1)/2) #切り上げ
        if A_wa[now]==A_use :  #A[i]がKと一致
            A_MAX = now #ここが最大
            break
        elif A_wa[now]<A_use : #A[i]がKより小さい
            start = now #目的の値はここ以上のとこにある
            A_MAX = now #現時点での最大値
        else : #A[i]がKより大きい
            end = now-1#目的の値はここより小さい
    ##Aの最大探すの終わり
    
    #これ最大？
    if A_MAX+i>ans :
        ans=A_MAX+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_wa = [0]
for i in range(N) :
    A_wa.append(A_wa[i]+A[i])

B_wa = [0]
for i in range(M) :
    B_wa.append(B_wa[i]+B[i])

#累積和計算おわり


ans = 0
end = N #二分探索の後に設定しなおしたいので先に設定しておく

for i in range(M+1):#Bを順番に増やしていくよー
    A_use = K-B_wa[i]
    if A_use<0: #Bだけでこえてる
        break
    
    ##Aは最大で何冊よめるかな
    A_MAX = 0
    start = 0
    while  end-start>=1 : #調べるのが2個以上
        now = int((start + end+1)/2) #切り上げ
        if A_wa[now]==A_use :  #A[i]がKと一致
            A_MAX = now #ここが最大
            break
        elif A_wa[now]<A_use : #A[i]がKより小さい
            start = now #目的の値はここ以上のとこにある
            A_MAX = now #現時点での最大値
        else : #A[i]がKより大きい
            end = now-1#目的の値はここより小さい
    ##Aの最大探すの終わり
    
    #これ最大？
    if A_MAX+i>ans :
        ans=A_MAX+i

    end=A_MAX #endの再設定

#コンソールにだす
print(ans)
# Original solution
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = list(map(int, open(0).read().split()))
    cum_A, cum_B = tuple(accumulate([0] + AB[:N])), tuple(accumulate(AB[N:]))
    res = 0
    for i, a_time in enumerate(cum_A):
        if a_time > K:
            break
        b_time = K - a_time
        res = max(res, i + bisect(cum_B, b_time))
    print(res)


if __name__ == "__main__":
    main()


# Optimized solution
# C - Tsundoku
from bisect import bisect
from itertools import accumulate


def main():
    N, M, K, *AB = list(map(int, open(0).read().split()))
    cum_A, cum_B = accumulate(AB[:N], initial=0), tuple(accumulate(AB[N:]))
    candidates = [0]
    for i, a in enumerate(cum_A):
        if a > K:
            break
        candidates.append(i + bisect(cum_B, K - a))
    print((max(candidates)))


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 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 a[i] + b[j] > k:
        j -= 1
    ans = max(ans, i+j)
print(ans)

# Optimized solution
import itertools

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

acc_A = [0]+list(itertools.accumulate(A))
acc_B = [0]+list(itertools.accumulate(B))
    
ans, j = 0, m
for i in range(n+1):
    if acc_A[i] > k:
        break
    while acc_A[i] + acc_B[j] > k:
        j -= 1
    ans = max(ans, i+j)
print(ans)
# Original solution
from bisect import bisect_right

n, m, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [0]
B = [0]
for i in range(n):
    A.append(A[-1] + a[i])
for j in range(m):
    B.append(B[-1] + b[j])
    
ans = 0
for i in range(n + 1):
    time = A[i]
    b_index = 0
    if time > k:
        break
    b_index = bisect_right(B, k - time)
    ans = max(ans, i + b_index - 1)
print(ans)

# Optimized solution
from bisect import bisect_right

n, m, k = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
A = [0]
B = [0]
for i in range(n):
    A.append(A[-1] + a[i])
for j in range(m):
    B.append(B[-1] + b[j])
    
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)