Harryxun/stf_run huggingface dataset:
from collections import*
z,v,a=input,range,print
h,w,k=map(int,z().split());r,s,t,u=map(lambda x:int(x)-1,z().split())
b=[z()for _ in v(h)];l=[[-1]*w for _ in v(h)];l[r][s]=0
d=deque([(r,s)])
while d:
  x,y=d.popleft();j=l[x][y]
  if(x==t)&(y==u):exit(a(j))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i;c=l[p][q]
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=v<=j:break
      if c<0:d+=[(p,q)];l[p][q]=j+1
a(-1)

### FIXED CODE ###

import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque()
now.append([x1-1,y1-1])
dp[x1-1][y1-1]=0
#kの更新が遅い
def bfs(d):
    global h,w,k,dp,now,x2,y2
    l=len(now)
    if l==0:
        return
    dp_sub=deque()
    cand=set()
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp_sub.append([x,y+j,d])
                #dp[x][y+j]=d
                cand.add((x,y+j))
                #now.append([x,y+j])
            else:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp_sub.append([x,y-j,d])
                #dp[x][y-j]=d
                cand.add((x,y-j))
                #now.append([x,y-j])
            else:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp_sub.append([x+j,y,d])
                #dp[x+j][y]=d
                cand.add((x+j,y))
                #now.append([x+j,y])
            else:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp_sub.append([x-j,y,d])
                #dp[x-j][y]=d
                cand.add((x-j,y))
                #now.append([x-j,y])
            else:
                break
    while dp_sub!=deque([]):
        e=dp_sub.popleft()
        dp[e[0]][e[1]]=e[2]
    for i in cand:
        now.append(i)
    bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)
from math import gcd
N, M = map(int, input().split(" "))
S = input()
T = input()
G = gcd(N, M)
L = N * M // G
for i in range(G):
  if S[i*N//G] != T[i*M//G]:
    print(-1)
    exit(0)
print(L)



### FIXED CODE ###

from fractions import gcd
N, M = map(int, input().split(" "))
S = input()
T = input()
G = gcd(N, M)
L = N * M // G
for i in range(G):
  if S[i*N//G] != T[i*M//G]:
    print(-1)
    exit(0)
print(L)
n=int(input())
if n%2==0:
  print(n)
else:
  print(2n)

### FIXED CODE ###

n=int(input())
if n%2==0:
  print(n)
else:
  print(2*n)
def exhaustive_search(start, Sum, answer):
    for i in range(start, n):
        Sum = Sum + A[i]
        if Sum == answer:
            return True
        elif Sum > answer:
            Sum = Sum - A[i]
            next
        else:
            r = exhaustive_search(i+1, Sum, answer)
            if r == True:
                return True
            else:
                Sum = Sum - A[i]
    return False


for i in M:
    r = exhaustive_search(0, 0, i)
    if r == True:
        print('yes')
    else:
        print('no')
print(' ')

### FIXED CODE ###

def solve(dp, a, i, m):
  if m in dp[i]:
    return dp[i][m]

  if m == 0:
    dp[i][m] = True
  elif i >= len(a):
    dp[i][m] = False
  elif solve(dp, a, i+1, m):
    dp[i][m] = True
  elif solve(dp, a, i+1, m-a[i]):
    dp[i][m] = True
  else:
    dp[i][m] = False

  return dp[i][m]

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

dp = {}
for i in range(N+1):
  dp[i] = {}

for m in M:
  if solve(dp, A, 0, m):
    print('yes')
  else:
    print('no')
N=int(input())
d=[int(s) for s in input().split(" ")]

d.sort()

if (N//2)%2==0:
    print(0)
else:
    K=d[(N//2)]-d[N//2-1]
    print(K

### FIXED CODE ###

N=int(input())
D=[int(s) for s in input().split()]

D=sorted(D)
sum=[]
count=0
for i in reversed(range(len(D))):
    sum.append(D.pop(i))
    if len(sum) == len(D):
        Ans=len(sum)
        break
for i in range(D[Ans-1],sum[Ans-1],1):
    count+=1
print(count)
s = input()
n = len(s)
counter = 0
for i in range(n//2):
    if s[i] != s[n-i-1]:
    counter += 1
print(counter)

### FIXED CODE ###

sam = input()
nancy = len(sam)
counter = 0
for i in range(nancy//2):
    if sam[i] != sam[nancy-i-1]:
        counter += 1
print(counter)
n = int(input())
h = list(map(int, input().split()))

dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[2]-h[1])

for i in range(2, n):
    dp[i] = dp[i-1] + abs(h[i]-h[i - 1])
    if i > 1:
        dp[i] = min(dp[i], dp[i-2] + abs(h[i]-h[i - 2]))

print(dp[n - 1])


### FIXED CODE ###

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

dp = [float("inf")] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i]-h[i - 1]), dp[i - 2] + abs(h[i]-h[i - 2]))

print(dp[n - 1])
h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

n = int(input())

arr = [[] for i in range(901)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]


for i in range(n):
	l,r = inputs[i]

	ans = 0

	t = 1
	while l + d * t <= r:
		ans += abs(arr[l+d*t][0] - arr[l+d*(t-1)][0]) + abs(arr[l+d*t][1] - arr[l+d*(t-1)][1])
		t += 1

	print ans

### FIXED CODE ###

h,w,d = map(int,raw_input().split())

field = []

for i in range(h):
	field.append(map(int,raw_input().split()))

distance = [0 for i in range(90001)]


n = int(input())

arr = [[] for i in range(90001)]

inputs = []

for i in range(n):
	inputs.append(map(int,raw_input().split()))


for i in range(h):
	for j in range(w):
		arr[field[i][j]] = [i+1,j+1]

for i in range(d+1,h*w+1):
	distance[i] = distance[i-d] + abs(arr[i][0] - arr[i-d][0]) + abs(arr[i][1] - arr[i-d][1])


for i in range(n):
	l,r = inputs[i]

	print distance[r]-distance[l]
s=input()

if s[0]=='A':
    if s[2:-1].count('C')==1:
        index=s[2:-1].index('C')
        if tmp==tmp.lower():
            print('AC')
        else:
            print('WA')
    else:
        print('WA')
else:
    print('WA')



### FIXED CODE ###

s=input()
print('AC' if 'C' in s[2:-1] and 'A' in s and s[1:].replace('C','',1).islower() else 'WA')
x,y = map(int,input().split())

X=int(x,16)
Y=int(y,16)

if X>Y:
  print(">")
elif X<Y:
  print("<")
else:
  print("=")

### FIXED CODE ###

x,y = input().split()
 
X=int(x,16)
Y=int(y,16)
 
if X>Y:
  print(">")
elif X<Y:
  print("<")
else:
  print("=")
# 計算量O(N2M)

N = int(input())

d = list(map(int,input().split()))
d_cnt = [0]*max(d)

for v in d:
    d_cnt[v-1] += 1

M = int(input())

t = list(map(int,input().split()))
t_cnt = [0]*max(t)

for v in t:
    t_cnt[v-1] += 1

if N < M:
    print('NO')
    exit()


for i in range(len(t_cnt)):
    if t_cnt[i] != 0:
        if d_cnt[i] < t_cnt[i]:
            print('NO')
            exit()

print('YES')


### FIXED CODE ###

# 計算量O(N2M)
import collections
N = int(input())

d = collections.Counter(list(map(int,input().split())))

M = int(input())
t = list(map(int,input().split()))
t_num = t.copy()
t_num = set(list(t_num))
t = collections.Counter(t)

if N < M:
    print('NO')
    exit()

for key in t_num:
    if d[key] < t[key]:
        print('NO')
        exit()
print('YES')
n = int(input())
ans = 0
for j in l:
    x, u = input().split()
    if u == 'JPY'
        ans += int(x)
    else:
        ans += float(x) * 380000
print(ans)


### FIXED CODE ###

n = int(input())
l = [input().split() for _ in range(n)]
ans = 0
for x, u in l:
    x = float(x)
    if u == 'JPY':
        ans += x
    else:
        ans += x * 380000
print(ans)
import math

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

def calc_theta(a, b, x):
    tmp = (a ** 3) / (2 * (a **2 * b - x))
    tmp2 = (2 * x) / (a ** 2 * b)
    return 90 - math.degrees(math.atan(tmp)), 90 - math.degrees(math.atan(tmp2))

ans1, ans2 = calc_theta(a, b, x)

print(ans1, ans2)

if ans2 > 45:
    print(ans2)
else:
    print(ans1)






### FIXED CODE ###

import math

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

def calc_theta(a, b, x):
    if x >= 0.5 * a ** 2 * b:
        # tmp = (a ** 3) / (2 * ((a **2) * b - x)) これだと 0divになる
        tmp = (2/a)*(b-(x/a**2))
    else:
        tmp = (a * b * b) / (2 * x)
    return math.degrees(math.atan(tmp))

ans = calc_theta(a, b, x)

print('{:.10f}'.format(ans))
from collections import defaultdict

N, M = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(M)]

g = defaultdict(list)
g2 = defaultdict(list)
done = [0] * (N+1)
memo = [0] * (N+1)
for x, y in xy:
    g[x].append(y)
    g2[y].append(x)

def dp2(v):
    max_len = 0
    if done[v] == 1:
        return memo[v]
    
    for i in g2[v]:
        max_len = max(max_len, dp2(i) + 1)
    done[v] = 1
    memo[v] = max_len
    return max_len
    
    
def dp(v):
    max_len = 0
    if done[v] == 1:
        return memo[v]
    else:
        for to in g[v]:
            max_len = max(max_len, dp(to)+1)
        done[v] = 1
        memo[v] = max_len
        return max_len

ans = 0
for v in range(1, N+1):
    ans = max(ans, dp2(v))
print(ans)

### FIXED CODE ###

from collections import defaultdict, deque

def topological_sort(vertex:list, edge:list):
    graph = {i: [] for i in vertex}
    for i, j in edge:
        graph[i].append(j)
        
    inp_cnt = defaultdict(int)
    outs = defaultdict(list)
    for inp, out in edge:
        inp_cnt[out] += 1
        outs[inp].append(out)

    result = []
    queue = deque([i for i in vertex if inp_cnt[i]==0])
    while queue:
        v = queue.popleft()
        result.append(v)
        for v2 in outs[v]:
            inp_cnt[v2] -= 1
            if inp_cnt[v2] == 0:
                queue.append(v2)
    return result

N, M = map(int, input().split())
vertex = list(range(1, N+1))
edge = [list(map(int, input().split())) for _ in range(M)]
graph = {i: [] for i in vertex}
for i, j in edge:
    graph[i].append(j)

sorted_vertecies = topological_sort(vertex, edge)
dp = [0] * (N+1)
for i in sorted_vertecies:
    ends = graph[i]
    for j in ends:
        dp[j] = max(dp[j], dp[i] + 1)
print(max(dp))
import math

x1,y1 = 0, 0

def fact(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

S = int(input())

list1 = sorted(fact(S))#おおきいのが最後

if int(list1[-1]) <= 10**9:
  f = list1[::-1]
  st = 1
  i = 0
  while (st <= 10**9)&(i<len(list1)):
    st *= list1[i]
    i += 1
  if st > 10**9:
    st = st//list1[i-1]
  x2,y2 = st,0
  x3,y3 = 0,S//st

else:
  list2 = []
  list2.append(int(S//list1[-1]))
  while list1[-1] > 10**9:
    dash = list1[-1]
    list1 = fact(dash + 1)
    list2.append(int((dash+1)//list1[-1]))

  sum2 = 0
  sum4 = 1
  for i in range(len(list2)-1):
    sum4 *= list2[i] 
    sum2 += sum4

  y2 = fact(sum2)[-1]
    
  b = list1[-1]
  x2 = b
  x3 = sum2//y2
  y3 = (S + x3*y2)//b
  s = x2*y3 - x3*y2
  
print(int(x1),int(y1),int(x2),int(y2),int(x3),int(y3))

### FIXED CODE ###

S = int(input())

if S == 10**18:
  x1,y1 = 0,0
  x2 = 10**9
  y3 = 10**9
  x3 = 0
  y2 = 0

else:
  x1, y1 = 0,0

#|x2y3-x3y2|=S

  x2 = 10**9
  y2 = 1

#|10**9y3-x3|= s

  y3 = (S//(10**9)) + 1
  x3 = (10**9)*y3 - S

print(int(x1),int(y1),int(x2),int(y2),int(x3),int(y3))
from fractions import gcd
import sys
sys.setrecursionlimit(10 ** 9)

def lcm(a, b):
  return a * b // gcd(a, b)

def llcm(a):
  if len(a) == 1:
    return a
  elif len(a) == 2:
    return lcm(a[0],a[1])
  else:
    return llcm(a[0],a[1:])
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
for a in A:
  if (a//2)%2 == 0:
    print(0)
    exit()
  else:
    B.add(a//2)

l = llcm(list(B))
#print(l)
if l > M:
  ans = 0
else:
  ans = 1+(M-l)//(2*l)
print(ans)


### FIXED CODE ###

from fractions import gcd

def lcm(a, b):
  return a * b // gcd(a, b)
  
N,M = map(int,input().split())
A = list(map(int,input().split()))

B = set()
l = 1
for i in range(len(A)):
  c = 0
  a = A[i]
  while(a%2 == 0):
    a //= 2
    c += 1
  if i == 0:
    c0 = c
  else:
    if c0 != c:
      print(0)
      exit()
  l = lcm(l,A[i]//2)

print((M+l)//(2*l))
import sys
sys.setrecursionlimit(10**6)

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

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

salist=[]
for i in range(1,len(balls),1):
  sax = balls[i][0]-balls[i-1][0]
  say = balls[i][1]-balls[i-1][1]
  if [sax,say] not in salist:
    salist.append([sax,say])

balls.reverse()
costs=[]
for i,sa in enumerate(reversed(salist)):
  cost=1
  for i in range(0,len(balls)-1,1):
    if balls[i+1][0]!=balls[i][0]-sa[0] and balls[i+1][1]!=balls[i][1]-sa[1]:
      cost+=1
  costs.append(cost)

print(min(costs))

### FIXED CODE ###

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

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

ans=0
for i in range(0,N-1):
  for j in range(i+1,N):
    sax = balls[j][0]-balls[i][0]
    say = balls[j][1]-balls[i][1]
    merge=0
    for k in range(0,N):
      if([balls[k][0]+sax,balls[k][1]+say] in balls):
          merge+=1
    ans=max(ans,merge)
print(N-ans)
from collections import defaultdict
import math

INF = 10 ** 5
is_prime = [1] * INF

def eratorasu():
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, INF):
        if is_prime[i] == 0:
            continue
        for j in range(i * 2, INF, i):
            is_prime[j] = 0
    return

def f(n):
    yakusu = []
    if is_prime[n]:
        yakusu.append(n)
    else:
        for i in range(2, int(n ** 0.5) + 1):
            if n % i == 0:
                yakusu.append(i)
                break

    for i in yakusu:
        if i != 1:
            d[i] += 1

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

tmp = A[0]
for i in range(1, N):
    tmp = math.gcd(tmp, A[i])
    f(A[i])

if tmp != 1:
    print('not coprime')
    exit()
eratorasu()
f(A[0])
for i, v in d.items():
    if v != 1:
        print('setwise coprime')
        exit()

print('pairwise coprime')


### FIXED CODE ###

from collections import defaultdict
import math

INF = 10 ** 6 + 1
is_prime = [1] * INF

def eratorasu():
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, INF):
        if is_prime[i] == 0:
            continue
        for j in range(i * 2, INF, i):
            is_prime[j] = 0
    return

def f(n):
    yakusu = []
    if is_prime[n]:
        yakusu.append(n)
    else:
        for i in range(2, int(n ** 0.5) + 1):
            if n % i == 0:
                yakusu.append(i)
                if i != n //i:
                    yakusu.append(n // i)
                break

    for i in yakusu:
        if i != 1:
            d[i] += 1

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

tmp = A[0]
for i in range(1, N):
    tmp = math.gcd(tmp, A[i])
    f(A[i])

if tmp != 1:
    print('not coprime')
    exit()
eratorasu()
f(A[0])

for i, v in d.items():
    if v != 1:
        print('setwise coprime')
        exit()

print('pairwise coprime')
N, x =map(int, input().split())
a = sorted(map(int, input().split()))

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
    i += 1

print(i)


### FIXED CODE ###

N, x =map(int, input().split())
a = sorted(map(int, input().split()))

i = 0

while (i<N) and (x>=0):
    x -= a[i]
    if x>=0:
        i += 1

if (i == N) and (x>0) :
    print(N-1)
else:
    print(i)
from math import ceil
H = int(input())
print(2**(ceil(H/2)+1)-1)

### FIXED CODE ###

H = int(input())
enemy = 1
count = 0
while H >= 1:
  count += enemy
  enemy *= 2
  H //= 2
print(count)
n, a, b = map(int, input().split())

ans = 0
for num in range(1, n + 1):
    s = str(num)
    sm = 0
    for let in s:
        sm += int(let)
    if a <= sm <= b:
        ans += num

print(cnt)


### FIXED CODE ###

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

ans = 0
for num in range(1, n + 1):
    s = str(num)
    sm = 0
    for let in s:
        sm += int(let)
    if a <= sm <= b:
        ans += num

print(ans)
x, k, d = map(int, input().split())
minus=False
if x<0:
    minus = True
x = abs(x)
s = x//d
if s==0:
    k%2==0:
        if minus==True
            print(-x)
        else: print(x)
    k%2==1:
        if minus==True
            print(-x+d)
        else: print(x-d)
elif s>k:
    if minus==True
        print(x-d*k)
    else: print(-x+d*k)
elif s<k:
    (k-s)%2==0:
        if minus==True
            print(-x+d*s)
        else: print(x-d*s)
    (k-s)%2==1:
        if minus==True
            print(-x+d*(s+1))
        else: print(x-d*(s+1))

### FIXED CODE ###

x, k, d = map(int, input().split())
x = abs(x)
s = x//d
if s>k:
    print(x-d*k)
elif s<=k:
    if (k-s)%2==0:
        print(x-d*s)
    elif (k-s)%2==1:
        print(abs(x-d*(s+1)))
n,x=map(int,input().split())
a=list(map(int,input().spit()))
a.sort()
ans=0
for i in range(n):
  if x>=a[i]:
    ans+=1
    x-=a[i]
print(ans)

### FIXED CODE ###

def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]
    
n,x=MI()
a=LI()
a.sort()
y=x
ans,s=0,0
for i in range(n):
    s+=a[i]
    if s>x:
        break
    else:
        if i<n-1:
            ans+=1
        elif x-s==0:
            ans+=1
            
print(ans)
s=int(input())
print("YES" any([str(i)*3 in str(s) for i in range(10)]) else "NO")


### FIXED CODE ###


s=int(input())
print("Yes" if any([str(i)*3 in str(s) for i in range(10)]) else "No" )
N,W = map(int, input().split())


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

Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

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

for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]






Wmin = min(w)

nap_memo ={}

def nap(i,W2):
    kagi = str(i) + ':' +str(W2)
    if kagi in nap_memo:
        return nap_memo[kagi]
    elif i ==0:
        r=0
    elif W2<Wmin:
        r=0
    elif W2 < Wmin:
        r=0
    elif W2 < w[i]:
        r=nap(i-1,W2)
    elif Wsum[i]<=W2:
        r=Vsum[1]
    else:
        r=max( nap(i-1,W2-w[i])+v[i],nap(i-1,W2))
        
    nap_memo[kagi]=r
    return r

print(nap(N,W))

### FIXED CODE ###


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


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

Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

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


Wmin = min(w)    
w.insert(0,"0")
v.insert(0,"0")
for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]



nap_memo ={}

def nap(i,W2):
    kagi = str(i) + ':' +str(W2)
    if kagi in nap_memo:
        return nap_memo[kagi]
    elif i ==0:
        r=0
    elif W2<Wmin:
        r=0
    elif W2 < w[i]:
        r=nap(i-1,W2)
    elif Wsum[i]<=W2:
        r=Vsum[i]
    else:
        r=max( nap(i-1,W2-w[i])+v[i],nap(i-1,W2))
        
    nap_memo[kagi]=r
    return r

print(nap(N,W))
# -*- coding: utf-8 -*-
# 標準入力を取得
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# 求解処理
ans = 0
n, m, k = 0, 0, 0
while True:
    if n >= N and m >= M:
        break
    if n >= N:
        k += B[m]
        if k > K:
            break
        ans += 1
        m += 1
        continue
    if m >= M:
        k += A[n]
        if k > K:
            break
        ans += 1
        n += 1
        continue
    A_n, B_m = A[n], B[m]
    if A_n < B_m:
        k += A_n
        n += 1
    elif A_n > B_m:
        k += B_m
        m += 1
    else:
        if n == N:
            k += B_m
            m += 1
        elif m == M:
            k += A_n
            n += 1
        else:
            A_nn, B_mm = A[n+1], B[m+1]
            if A_nn <= B_mm:
                k += A_n
                n += 1
            else:
                k += B_m
                m += 1
    if k > K:
        break
    ans += 1

# 結果出力
print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
# 標準入力を取得
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 b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

# 結果出力
print(ans)
K, N = map(int, input().split())
A = list(map(int, input().split()))

ans_root = K
for i range(N):
    if i==0:
        root = A[N-1] - A[0]
    else:
        root = A[i-1]+K - A[i]
    if ans_root > root:
        ans_root = root
print(ans_root)

### FIXED CODE ###

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

ans_root = K
for i in range(N):
    if i==0:
        root = A[N-1] - A[0]
    else:
        root = A[i-1]+K - A[i]
    if ans_root > root:
        ans_root = root
print(ans_root)
import sys

nums = []


for line in sys.stdin:
    nums.append(line)

for i in range(len(nums)):
    input_line = nums[i].split(" ")
    a = long(input_line[0])
    b = long(input_line[1])


    #??¬?´???°?????????
    common_div = []

    #?????§??¬?´???°
    if a < b:
        last_num = a
    else:
        last_num = b

    for j in range(1,last_num-1):
        if a%j == 0 and b%j == 0:
            #a???b???j??§???????????¨???
            common_div.append(j)
    
    max_common_div = common_div[len(common_div)-1]
    min_common_mpl = int((a * b)/max_common_div)

    print(str(max_common_div) + " " + str(min_common_mpl))

    

### FIXED CODE ###

import sys
 
nums = []
 
 
for line in sys.stdin:
    nums.append(line)
 
for i in range(len(nums)):
    input_line = nums[i].split(" ")
    a = int(input_line[0])
    b = int(input_line[1])
 
    if a > b:
        num_bigger = a
        num_smaller = b
    else:
        num_bigger = b
        num_smaller = a

    r = 1   #?????????
    while r > 0:
        r = num_bigger % num_smaller
        num_bigger = num_smaller
        num_smaller = r

    max_common_div = num_bigger
    min_common_mpl = int((a * b)/max_common_div)
 
    print(str(max_common_div) + " " + str(min_common_mpl))
N, K = map(int,input().split())
S = input()
S[K-1] = S[K-1].lower()
print(''.join(S))

### FIXED CODE ###

N, K = map(int, input().split())
S = list(input())
S[K-1] = S[K-1].lower()
print("".join(S))
n_len = int(input())
n_list = [int(x) for x in input().split()]
n_border = 0
    

for ind in range(n_len - 1):
    n1 = n_list[ind]
    n2 = n_list[ind+1]
    print(n1,n2,n_border)
    if n1 - 1 > n_border:
        n_border = n1 - 1
    if (n1 - 1 <= n2) & (n_border <= n2):
        pass
    else:
        flag = 1
        break
        
if flag:
    print('No')
else:
    print('Yes')

### FIXED CODE ###

n_len = int(input())
n_list = [int(x) for x in input().split()]
flag = 0

n_border = 0

for ind in range(n_len - 1):
    n1 = n_list[ind]
    n2 = n_list[ind+1]
    if n1 - 1 > n_border:
        n_border = n1 - 1
    #print(n1,n2,n_border)
    if (n1 <= n2) | (n1 - 1 <= n2) & (n_border <= n2):
        pass
    else:
        flag = 1
        break
        
if flag:
    print('No')
else:
    print('Yes')
n=int(input())
aa=map(int,input().split())
aa=list(aa)
memo=[]
count=0
for a in aa:
    if a<400:memo.append(1)
    elif a<800:memo.append(2)
    elif a<1200:memo.append(3)
    elif a<1600:memo.append(4)
    elif a<2000:memo.append(5)
    elif a<2400:memo.append(6)
    elif a<2800:memo.append(7)
    elif a<3200:memo.append(8)
    else:count+=1

memo=set(memo)
min=len(memo)
if min=0:min=1
max=len(memo)+count
if max>8: max=8
print(min,max)

### FIXED CODE ###

n=int(input())
aa=map(int,input().split())
aa=list(aa)
memo=[]
count=0
for a in aa:
    if a<400:memo.append(1)
    elif a<800:memo.append(2)
    elif a<1200:memo.append(3)
    elif a<1600:memo.append(4)
    elif a<2000:memo.append(5)
    elif a<2400:memo.append(6)
    elif a<2800:memo.append(7)
    elif a<3200:memo.append(8)
    else:count+=1

memo=set(memo)
min=len(memo)
if min==0:min=1
max=len(memo)+count
#if max>8: max=8
print(min,max)