Harryxun/stf_run huggingface dataset:
a = int(input())
y = a//100
m = a%100
if y <= 12 and y >= 1:
	if m <= 12 and n >= 1:
    	print('AMBIGUOUS')
    else:
     	print('MMYY')
else:
	if m <= 12 and n >= 1:
    	print('YYMM')
    else:
     	print('NA')


### FIXED CODE ###

a, b = map(int, input().split())
c = input()
print(c[:b-1]+str.lower(c[b-1])+c[b:])
print("No" if int(input())*500<int(input()) else "yes")

### FIXED CODE ###

k,x=map(int,input().split())
print("No" if k*500<x else "Yes")
import math
a, b, c=input().split(" ")
a = float(a) 
b = float(b)
c = float(c) 
if  a*b < ((c-a-b)/2)*((c-a-b)/):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

import math
a, b, c=input().split(" ")
a = int(a) 
b = int(b)
c = int(c) 

if  4*a*b < (c-a-b)*(c-a-b) and (c-a-b)>0:
  print("Yes")
else:
  print("No")
from sys import stdin
mod = 10**9+7
X,Y = [int(x) for x in stdin.readline().rstrip().split()]

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2

    return K * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def fact(n):
    f = 1
    for i in range(1,n+1):
        f *= i
        f %= mod
    return f

flag = True
if X == 0 or Y == 0:
    flag = False
x = 0
y = 0
x += min(X//3,Y//3)
y += min(X//3,Y//3)
tmp = min(X//3,Y//3)
X = X-tmp*3
Y = Y-tmp*3
if X == 0 and Y == 0:
    X = X
    Y = Y
elif (Y % (X*2) == 0):
    y += (Y//2)

elif (X % (Y*2) == 0):
    x += (X//2)
else:
    flag = False

if flag:
    ans = fact(x+y)
    ans = div(ans,fact(x))
    ans = div(ans,fact(y))
    print(ans%mod)
    
else:
    print(0)

### FIXED CODE ###

from sys import stdin
import numpy as np
mod = 10**9+7
X,Y = [int(x) for x in stdin.readline().rstrip().split()]

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
 
def power(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1
 
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2
 
    return K * x % mod
 
def div(a, b):
    return mul(a, power(b, mod-2))
 
def fact(n):
    f = 1
    for i in range(1,n+1):
        f *= i
        f %= mod
    return f

if (X+Y) % 3 != 0:
    print(0)

else:
    A = np.matrix([[2, 1],[1, 2]])
    Y = np.matrix([[X],[Y]])
    x,y = np.linalg.solve(A,Y)
    x = int(x)
    y = int(y)
    ans = fact(x+y)
    ans = div(ans,fact(x))
    ans = div(ans,fact(y))
    if x < 0 or y <0:
        print(0)
    else:
        print(ans%mod)
s = list(input())
odd = []
even = []
for i in range(len(s)):
  if i % 2 == 0:
    odd.aapend(s[i])
  else:
    even.append(s[i])
o = 0
e = 0
if "L" in odd:
  o = -1
if "R" in even:
  e = -1
if o * e == 0:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

s = list(input())
odd = []
even = []
for i in range(len(s)):
  if i % 2 == 0:
    odd.append(s[i])
  else:
    even.append(s[i])
if "L" in odd or "R" in even:
  print("No")
else:
  print("Yes")
A,B,K=(int(i) for i in input().split())
L=list(range(A,B+1))
a=B-A+1
if K>=a:
  for i in range(a):
    print(L[i])
else:
  S=list(set(L[:K]+L[a-K:a]))
  S.sort()
  for i in S:
    print(i)

### FIXED CODE ###

A,B,K=(int(i) for i in input().split())
a=B-A+1
if K>=a:
  for i in range(A,B+1):
    print(i)
else:
  L1=list(range(A,A+K))
  L2=list(range(B-K+1,B+1))
  S=list(set(L1+L2))
  S.sort()
  for i in S:
    print(i)
x,n=map(int,,input().split())
a=sorted(list(map(int,input().split())))
if n==0:
  print(x)
  exit()
else:
  for i in range(100):
    aa=x-i
    if aa not in a:
      print(aa)
      exit()
    bb=x+i
    if bb not in a:
      print(bb)
      exit()
    
    

### FIXED CODE ###

x,n=map(int,input().split())
a=sorted(list(map(int,input().split())))
if n==0:
  print(x)
  exit()
else:
  for i in range(100):
    aa=x-i
    if aa not in a:
      print(aa)
      exit()
    bb=x+i
    if bb not in a:
      print(bb)
      exit()
data = input()

sc = 0
ans = []
if (data[0] == data[1]) & (data[0] == data[2]):
    data = int(data)
    print(*data)
elif int(data[0]) > int(data[1]):
    sc = int(data[0])
    ans = 100 * sc + 10 * sc + sc
    print(ans)
else:
    sc = int(data[0]) + 1
    ans = 100* sc + 10 * sc + sc
    print(ans)


    
    


### FIXED CODE ###

data = input()

sc = 0
ans = []
if (data[0] == data[1]) & (data[0] == data[2]):
    data = int(data)
    print(data)
elif int(data[0]) > int(data[1]):
    sc = int(data[0])
    ans = 100 * sc + 10 * sc + sc
    print(ans)
elif int(data[0]) == int(data[1]):
    if int(data[1]) > int(data[2]):
        sc = int(data[0])
        ans = sc * 100 + sc * 10 + sc
        print(ans)
    else :
        sc = int(data[0]) + 1
        ans = 100* sc + 10 * sc + sc
        print(ans)


        
else:
    sc = int(data[0]) + 1
    ans = 100* sc + 10 * sc + sc
    print(ans)
import sys
import math
from collections import deque
n,m = map(int, input().split())

q = [0]*(n+1)

graph = [[] for _ in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

if m == 0:
    print(0)
    exit()

d = deque()
a = 0
for l,j in enumerate(q):
    b = set()
    if j == 0:
        d.append(l)
        while d:
            v = d.popleft()
            b.add(v)
            q[i] = -1

            for i in graph[v]:
                b.add(i)
                q[i] = -1
                
                if dist[i] != -1:
                    continue
                dist[i] = dist[v] + 1
                d.append(i)
        a = max(a,len(b))
print(a)

### FIXED CODE ###

import sys
import math
from collections import deque
n,m = map(int, input().split())

q = [0]*(n+1)

graph = [[] for _ in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

if m == 0:
    print(1)
    exit()

d = deque()
a = 0
for l,j in enumerate(q):
    b = set()
    if j == 0:
        d.append(l)
        while d:
            v = d.popleft()
            b.add(v)
            q[v] = -1

            for i in graph[v]:
                b.add(i)
                q[i] = -1

                if dist[i] != -1:
                    continue
                dist[i] = dist[v] + 1
                d.append(i)
        a = max(a,len(b))
print(a)
import sys
sys.setrecursionlimit(10**5)

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

cost_list=[0 for _ in range(N)]

def cost(k):
    if k==0:
        result=0
    elif k==1:
        result=abs(H[1]-H[0])
    elif cost_list[k]>0:
        result=cost_list[k]
    else:
        result=min(cost(k-1)+abs(H[k]-H[k-1]),cost(k-2)+abs(H[k]-H[k-2]))
        cost_list[k]=result
    
    return result

print(cost(N-1))



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

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

cost_list=[0 for _ in range(N)]

cost_list[1]=abs(H[1]-H[0])

if N==2:
    print(cost_list[1])

else:
    for k in range(2,N):
        cost_list[k]=min(cost_list[k-1]+abs(H[k]-H[k-1]),cost_list[k-2]+abs(H[k]-H[k-2]))

    print(cost_list[N-1])
print('YES' if input() == input()[::-1])

### FIXED CODE ###

print('YES' if input() == input()[::-1] else 'NO')
import math
def find(a):
    ans = a[0]
    for i in range(1,len(a)):
        ans = ((ans)//(math.gcd(ans,a[i])) * a[i])
    return ans            
	


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

lcm = find(a)
ans = 0
mod = pow(10,9)+7
for i in a:
	ans = ans + lcm//i
	
print(ans%mod)	


### FIXED CODE ###

from fractions import gcd
def find(a):
    ans = a[0]
    for i in range(1,len(a)):
        ans = ((ans)//(gcd(ans,a[i])) * a[i])
    return ans            
	


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

lcm = find(a)
ans = 0
mod = pow(10,9)+7
for i in a:
	ans = ans + lcm//i
	
print(ans%mod)
import sys
from itertools import accumulate

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

current_arr = A
if K > 41:
    print(*([N]*N))
else:
    for _ in range(K):
        imos = [0] * N
        ruiseki = [0] * (N+1)
        for i, ai in enumerate(current_arr):
            imos[max([0, i-ai])] += 1
            if i+ai+1 < N:
                imos[i+ai+1] -= 1
        for j, im in enumerate(imos):
            ruiseki[j+1] = ruiseki[j] + im
        current_arr = ruiseki[1:]
#print(imos)
#print(ruiseki)
#print(*accumulate(imos))
    print(*current_arr)


### FIXED CODE ###

S = input()
print(S[:3])
S = [x for x in input().rstrip()]

if S[0]==S[1] and S[1]!=S[2] and S[2]==S[3]:
    print("Yes")
elif S[0]==S[2] and S[1]!=S[2] and S[1]==S[3]:
    print("Yes")
elif S[0]==S[3] and S[2]!=S[3] and S[1]==S[2]:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

S = [x for x in input().rstrip()]

if S[0]==S[1] and S[1]!=S[2] and S[2]==S[3]:
    print("Yes")
elif S[0]==S[2] and S[1]!=S[2] and S[1]==S[3]:
    print("Yes")
elif S[0]==S[3] and S[2]!=S[3] and S[1]==S[2]:
    print("Yes")
else:
    print("No")
import math
n = input()
a = list(map(int, input().split()))
ans = float('inf')
for i in a:
    ans = min(ans, len(bin(i) - bin(i).rfind('1') - 1)
print(round(ans))


### FIXED CODE ###

import math
n = input()
a = list(map(int, input().split()))
ans = float('inf')
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind('1') - 1)
print(round(ans))
N = int(input())
T, A = np.array(input().split(), dtype="int")[:2]
H = [int(i) for i in input().split()]
    
min_dif = 10000
place = 0
for i in range(N):
  temp = T - H[i] *0.006
  dif = abs(A-temp)
        
  #誤差の最小値(→候補地も更新)
  if min_dif >= dif:
    min_dif = dif
    place = i+1
    
print(place)

### FIXED CODE ###

import numpy as np

def palace():
    
    N = int(input())
    T, A = np.array(input().split(), dtype="int")[:2]
    H = [int(i) for i in input().split()]
    
    min_dif = 10000
    place = 0
    for i in range(N):
        temp = T - H[i] *0.006
        dif = abs(A-temp)
        
        #誤差の最小値(→候補地も更新)
        if min_dif >= dif:
            min_dif = dif
            place = i+1
    
    print(place)
    
    
palace()
s = int(input())
if s == 'SAT':
    print(1)
if s == 'FRI':
    print(2)
if s == 'THU':
    print(3)
if s == 'WED':
    print(4)
if s == 'TUE':
    print(5)
if s == 'MON':
    print(6)
if s == 'SUN':
    print(7)

### FIXED CODE ###

s = input()
if s == 'SAT':
    print(1)
if s == 'FRI':
    print(2)
if s == 'THU':
    print(3)
if s == 'WED':
    print(4)
if s == 'TUE':
    print(5)
if s == 'MON':
    print(6)
if s == 'SUN':
    print(7)
N = int(input())
S = input
res = -1
for i in range(N):
  res = max(len(set(S[:i]) & set(S[i:])), res)
print(res)
  

### FIXED CODE ###

N = int(input())
S = input()
res = -1
for i in range(N):
  res = max(len(set(S[:i]) & set(S[i:])), res)
print(res)
import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=-m[0]//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[1]):
  ans+=-m[i]
print(ans)

### FIXED CODE ###

import heapq

n=list(map(int,input().split()))
m=list(map(int,input().split()))
m = [-x for x in m]
heapq.heapify(m)

for i in range(n[1]):
  x=(-1*m[0])//2
  heapq.heappop(m)
  heapq.heappush(m, -x)

ans=0
for i in range(n[0]):
  ans+=-m[i]

print(ans)
x = int(inpt())
if(x >= 30):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

x = int(input())
if(x >= 30):
    print("Yes")
else:
    print("No")
# dpに最大桁数を持たせる
N,M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

# dp[i]: マッチi本数で作れる最大の桁数(int)
dp = [-float('inf')]*(N+1)
dp[0] = 0
for i in range(N+1):
    nxt = dp[i]
    for aj in A:
        nxt = max(nxt, 
                  dp[i-f[aj]] + 1)
    dp[i] = nxt
    #print(dp)
#print(dp[N])
keta = dp[N]
ans = ""
matchs = N
# 上位の桁から貪欲に
while keta>0:
    for aj in A:
        if dp[matchs-f[aj]] == keta-1:
            ans += str(aj)
            matchs -= f[aj]
            keta -= 1
            break
print(ans)

### FIXED CODE ###

N,M = map(int, input().split())
A = list(map(int, input().split()))
dp = [None]*(N+1)
dp[0] = ""
f = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed

def max_str(s1:str, s2:str)->str:
    """return bigger one"""
    l1, l2 = len(s1), len(s2)
    if l1 != l2:
        return s1 if l1>l2 else s2
    if l1 == l2: 
        return s1 if s1>s2 else s2
    
for i in range(2, N+1):
    nxt = ""
    for aj in A:
        if i-f[aj]<0 or dp[i-f[aj]]==None: continue
        nxt = max_str(nxt, 
                      dp[i-f[aj]]+str(aj))
    if nxt!="":
        dp[i] = nxt
    #print(dp)
print(dp[N])
from numpy import array
from numpy.linalg import solve

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

L=[]
for i in range(N-1):
	L.append ([0]*i+[1,1]+[0]*(N-i-2)) 

L.append([1]+[0]*(N-2)+[1])


a=array(L) 
b=array(A)       
L=solve(a,b) 

for ans in L:
	print (int(ans)*2, end=" ")


### FIXED CODE ###

import sys
from collections import deque

N=input()
A=map(int, sys.stdin.readline().split())
A=map(lambda x: x*2, A)

a=sum(A)/2

for i in range(1,N):
	if i%2==1:
		a-=A[i]

#a
print a,

prev=a
for x in A[:-1]:
	x-=prev
	print x,
	prev=x
#-*-coding:utf-8-*-

import sys
import numpy as np

def choose_activity(idx,data,tmp):
    del data[idx]
    activity=max(data)
    idx=data.index(max(data))
    tmp.append(idx)
    return idx,activity

def main():
    n = int(input())
    datas=list([[int(i) for i in input().split()] for _ in range(n)])
    tmp=[]
    activity=[]

    for idx,data in enumerate(datas):
        if len(activity)==0:
            activity.append(max(data))
            tmp.append(data.index(max(data)))
        else:
            idx,data=choose_activity(tmp[idx-1],data,tmp)
            activity.append(data)
            tmp.append(data)
    print(sum(activity))

if __name__ == "__main__":
    main()

### FIXED CODE ###

"""
task statement
==============

明日から太郎君の夏休みが始まります。
太郎君は夏休みの計画を立てることにしました。
夏休みは N 日からなります。
各 i (1 \leq i \leq N) について、i 日目には太郎君は次の活動のうちひとつを選んで行います。

A: 海で泳ぐ。 幸福度 a_i を得る。
B: 山で虫取りをする。 幸福度 b_i を得る。
C: 家で宿題をする。 幸福度 c_i を得る。

太郎君は飽き性なので、2 日以上連続で同じ活動を行うことはできません。
太郎君が得る幸福度の総和の最大値を求めてください。

io_style
-------
N
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N
"""
#-*-coding:utf-8-*-

import sys

def main2():
    n = int(input())
    dp=[[0,0,0] for _ in range(n+1)]
    for i in range(n):
        a,b,c=map(int,input().split())
        dp[i+1][0]=max(dp[i][1],dp[i][2])+a
        dp[i+1][1]=max(dp[i][0],dp[i][2])+b
        dp[i+1][2]=max(dp[i][0],dp[i][1])+c
    print(max(dp[-1]))

if __name__ == "__main__":
    main2()
for e in iter(input,'0'):
 a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0])
 b=sorted([tuple(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0])
 for s,t in b:
  u,v=a[0]
  x,y=s-u,t-v
  for u,v in a:
   if (u+x,v+y)not in b:break
  else:print(x,y)


### FIXED CODE ###

for e in iter(input,'0'):
 a=[[*map(int,input().split())]for _ in[0]*int(e)]
 s,t=min(a)
 b={tuple(map(int,input().split()))for _ in[0]*int(input())}
 m=max(b)[0]-max(a)[0]+s
 for x,y in b:
  if x<=m:
   for u,v in a:
    if(x+u-s,y+v-t)not in b:break
   else:print(x-s,y-t);break
zenhan = int(S[:2])
kouhan = int(S[2:])
if zenhan == 0 or kouhan == 0:
    print('NA')
elif zenhan > 12 and kouhan > 12:
    print('NA')
elif zenhan <= 12 and kouhan <= 12:
    print('AMBIGUOUS')
elif zenhan <= 12 and kouhan > 12:
    print('MMYY')
elif zenhan > 12 and kouhan <= 12:
    print('YYMM')

### FIXED CODE ###

S = input()
zenhan = int(S[:2])
kouhan = int(S[2:])
if zenhan == 0 and kouhan != 0:
    if kouhan <= 12:
        print('YYMM')
    else:
        print('NA')
elif kouhan == 0 and zenhan != 0:
    if zenhan <= 12:
        print('MMYY')
    else:
        print('NA')
elif zenhan == 0 and kouhan == 0:
    print('NA')
elif zenhan > 12 and kouhan > 12:
    print('NA')
elif zenhan <= 12 and kouhan <= 12:
    print('AMBIGUOUS')
elif zenhan <= 12 and kouhan > 12:
    print('MMYY')
elif zenhan > 12 and kouhan <= 12:
    print('YYMM')
X=int(input())
g=X//500
h=X-g
i=h//5
j=1000*g+5*i
input(j)

### FIXED CODE ###

X=int(input())
g=X//500
h=X-500*g
i=h//5
j=1000*g+5*i
print(j)
N = int(input())
data = {}
bits = 0
bit_table = [set() for _ in range(31)]
for a in map(int, input().split()):
	bits |= a
	if a in data:
		data[a] += 1
	else:
		data[a] = 1
	i = 0
	while a:
		if a % 2 == 1:
			bit_table[i].add(a)
		a //= 2
		i += 1

def pop(data, a):
	if a in data:
		if data[a] == 1:
			del data[a]
		else:
			data[a] -= 1
		return a
	else:
		return None

def check2(data0, a1, a2):
	if (a1 | a2) != bits:
		return False
	
	data = { k: data0[k] for k in data0 }
	a0 = a1
	pop(data, a1)
	pop(data, a2)
	
	while data:
		a3 = a1 ^ a2
		a4 = pop(data, a3)
		if a4 == None:
			return False
		a1 = a2
		a2 = a3
	return a0 == (a1 ^ a2)

def check(data):
	keys = data.keys()
	for a1 in keys:
		b = bits & (~a)
		cands = None
		i = 0
		while b:
			if b % 2 == 1:
				if cands == None:
					cands = bit_table[i]
				else:
					cands &= bit_table[i]
			b //= 2
			i += 1
		
		for a2 in cands:
			if a1 != a2 or data[a1] > 1:
				if check2(data, a1, a2):
					return True
	return False

if check(data):
	print("Yes")
else:
	print("No")


### FIXED CODE ###

N = int(input())
data = {}
bits = 0
bit_table = [set() for _ in range(31)]
for a in map(int, input().split()):
	bits |= a
	if a in data:
		data[a] += 1
	else:
		data[a] = 1
	i = 0
	b = a
	while b:
		if b % 2 == 1:
			bit_table[i].add(a)
		b //= 2
		i += 1

def pop(data, a):
	if a in data:
		if data[a] == 1:
			del data[a]
		else:
			data[a] -= 1
		return a
	else:
		return None

def check2(data0, a1, a2):
	if (a1 | a2) != bits:
		return False
	
	data = { k: data0[k] for k in data0 }
	a0 = a1
	pop(data, a1)
	pop(data, a2)
	
	while data:
		a3 = a1 ^ a2
		a4 = pop(data, a3)
		if a4 == None:
			return False
		a1 = a2
		a2 = a3
	return a0 == (a1 ^ a2)

def check(data):
	keys = list(data.keys())
	a1 = keys[0]
	b = bits & (~a1)
	cands = set(keys)
	i = 0
	while b:
		if b % 2 == 1:
			cands &= bit_table[i]
		b //= 2
		i += 1
	
	for a2 in cands:
		if a1 != a2 or data[a1] > 1:
			if check2(data, a1, a2):
				return True
	return False

if check(data):
	print("Yes")
else:
	print("No")
n, a, b, c, d = map(int, input().split())
s = input()

if c < d:
    for i in range(b-1, d-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

    t = ''
    for i in range(len(s)):
        if i == d-1:
            t += '#'
        else:
            t += s[i]

    for i in range(a-1, c-1):
        if t[i] == '#' and t[i+1] == '#':
            print('No')
            exit()

    print('Yes')
elif c > d:
    for i in range(a-1, c-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

for bi in range(b-1,d):
    if s[bi-1] == s[bi] == s[bi+1] == '.':
        print('Yes')
        exit()

else:
    print('No')

### FIXED CODE ###

n, a, b, c, d = map(int, input().split())
s = input()

if c < d:
    for i in range(b-1, d-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

    t = ''
    for i in range(len(s)):
        if i == d-1:
            t += '#'
        else:
            t += s[i]

    for i in range(a-1, c-1):
        if t[i] == '#' and t[i+1] == '#':
            print('No')
            exit()

    print('Yes')
elif c > d:
    for i in range(a-1, c-1):
        if s[i] == '#' and s[i+1] == '#':
            print('No')
            exit()

    for bi in range(b-1,d):
        if s[bi-1] == s[bi] == s[bi+1] == '.':
            print('Yes')
            exit()

    print('No')

else:
    print('No')
import numpy as np
M,N,K = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
B = [int(hoge) for hoge in input().split()]
S = 0
Abook = 0
Bbook = 0
curbook = 0
for a in A:
    if S + a <= K:
        Abook += 1
        curbook += 1
        S += a
nextB = 0
for n,b in enumerate(B):
    if S + b <= K:
        Bbook += 1
        curbook += 1
        S += b
    else:
        nextB = n
        break
ans = curbook

for i in range(Abook):
    Abook -= 1
    curbook -= 1
    S -= A[Abook]
    for b_index in range(nextB,len(B)):
        if S + B[b_index] <= K:
            Bbook += 1
            curbook += 1
            S += B[b_index]
        else:
            nextB = b_index
            break
    ans = max(ans,curbook)
print(ans)

### FIXED CODE ###

M,N,K = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
B = [int(hoge) for hoge in input().split()]
S = 0
Abook = 0
Bbook = 0
curbook = 0
for a in A:
    if S + a <= K:
        Abook += 1
        curbook += 1
        S += a
    else:
        break
nextB = 0
for n,b in enumerate(B):
    if S + b <= K:
        Bbook += 1
        curbook += 1
        S += b
    else:
        nextB = n
        break
if Abook == len(A) and Bbook == len(B):
    print(len(A) + len(B))
    exit()

ans = curbook
for i in range(Abook):
    Abook -= 1
    curbook -= 1
    S -= A[Abook]
    for b_index in range(nextB,len(B)):
        if S + B[b_index] <= K:
            Bbook += 1
            curbook += 1
            S += B[b_index]
            nextB += 1
        else:
            nextB = b_index
            break
    ans = max(ans,curbook)
print(ans)
# AtCoder
from collections import defaultdict
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
ans = [0]*N

d = defaultdict(list)
for i in range(M):
    s = sc[i][0]
    c = sc[i][1]

    d[s].append(c)

for k, v in d.items():
    if list(set(v)) == v and len(v) >= 2:
        print(-1)
        exit()
    else:
        ans[k-1] = v[-1]

if (ans[0] == 0 and ans[1] == 0) or ans[0] == 0:
    print(-1)
    exit()

print(''.join(map(str, ans)))


### FIXED CODE ###

# AtCoder
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]


def isValid(n):
    sn = str(n)
    if len(sn) != N:
        return False
    for s, c in sc:
        if sn[s-1] != str(c):
            return False
    return True


for i in range(1000):
    if isValid(i):
        print(i)
        exit()
print(-1)
n = int(input())
data = []
for i in range(n):
    x, l = map(int, input().split())
    data.append([x, l])
data = sorted(data, key = lambda x: x[0])
i = 1
while 1:
    if data[i][0] - data[i][1] < data[i - 1][0] + data[i - 1][1]:
        del data[i]
    else:
        i += 1
    if i >= len(data) - 1:
        break
print(len(data))

### FIXED CODE ###

n = int(input())
data = []
for i in range(n):
    x, l = map(int, input().split())
    data.append([x, l])
data = sorted(data, key = lambda x: x[0] + x[1])
ans = 0
pre = -(10 ** 10)
for i in range(n):
    if data[i][0] - data[i][1] >= pre:
        ans += 1
        pre = data[i][0] + data[i][1]

print(ans)
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
k = int(input())
lunlun = []


@lru_cache(maxsize=100000000)
def func(i):
    if int(i) > 3234566667 + 10 or len(i) > 6:
        return
    lunlun.append(int(i))
    f = int(i[0])
    b = int(i[-1])
    if f != 0:
        func(f'{f-1}{i}')
    if f != 9:
        func(f'{f+1}{i}')
    func(f'{f}{i}')
    if b != 0:
        func(f'{i}{b-1}')
    if b != 9:
        func(f'{i}{b+1}')
    func(f'i}{b}')


for i in range(10):
    func(str(i))
lunlun = sorted(set(lunlun))
print(len(lunlun))
print(lunlun[k])


### FIXED CODE ###

from collections import deque

k = int(input())
q = deque(range(1, 10))
for _ in range(k):
    x = q.popleft()
    r = x % 10
    if r != 0:
        q.append(10*x + (r - 1))
    q.append(10*x+r)
    if r != 9:
        q.append(10*x + (r + 1))
print(x)
from sympy import nextprime

X=int(input())
print(nextprime(X))


### FIXED CODE ###

import math

P_lst=[2]
for i in range(1000):
  flag=0
  for j in P_lst:
    if (i+3)%j==0:
      flag=1

  if flag==0:
    P_lst.append(i+3)

X=int(input())

while X<=200000:
  if X==2:
    print(2)
    break
  flag=0
  x=math.sqrt(X)
  for k in P_lst:
    if X%k==0:
      break
    if x<k:
      flag=1
      break
  if flag==1:
    print(X)
    break
  X=X+1