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

import sys
readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readints():return list(map(int,readline().split()))

h,w = readints()

start = readints()
start = (start[0]-1)*w + start[1]-1

goal = readints()
goal = (goal[0]-1)*w + goal[1]-1

maze = [readstr() for i in range(h)]

dist = [10**10]*(h*w)

a = [[]for i in range(2)]
i = 0
a[i].append(start)
dist[start] = 0

while a[0] or a[1]:
    p = a[i].pop()
    y = p//w
    x = p%w
    for dy in range(-2,3):
        for dx in range(-2,3):
            if 0<=y+dy<h and 0<=x+dx<w and maze[y+dy][x+dx]=='.':
                q = (y+dy)*w + x+dx
                if dist[q]<=dist[p]:
                    continue
                if abs(dy)+abs(dx)==1:
                    a[i].append(q)
                    dist[q] = dist[p]
                else:
                    a[i-1].append(q)
                    dist[q] = dist[p] + 1
    if not a[i]:
        i = [1,0][i]

print(-1 if dist[goal]==10**10 else dist[goal])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import heapq
def dijkstra(s,path):
    # 距離をinfで初期化
    d = [float('inf')]*len(path)
    d[s] = 0

    # sへの距離は0
    q = [(0,s)]
    heapq.heapify(q)

    # 距離が最小の頂点から更新していけば良い
    while q:
        c,p = heapq.heappop(q)

        # 頂点pまでの距離がheap内のpまでの距離より小さい場合、continue
        if d[p]<c:
            continue

        # 頂点pから伸びる、全ての辺の距離を確認
        for to,cost in path[p]:
            # 頂点pから行ける頂点の距離がpまでの距離とpからの距離の和より小さい場合 -> 距離を更新し、heapに追加
            if d[to] > d[p] + cost:
                d[to] = d[p] + cost
                heapq.heappush(q,(d[to], to))
    return d

h,w = readints()

start = readints()
start = (start[0]-1)*w + start[1]-1

goal = readints()
goal = (goal[0]-1)*w + goal[1]-1

maze = [readstr() for i in range(h)]

path = [[] for i in range(h*w)]
for i in range(h*w):
    y = i//w
    x = i%w
    if maze[y][x]=='#':
        continue
    for dy in range(-2,3):
        for dx in range(-2,3):
            if dy==dx==0:
                continue
            if 0<=y+dy<h and 0<=x+dx<w and maze[y+dy][x+dx]=='.':
                j = (y+dy)*w + x+dx
                if (dy==0 and abs(dx)==1) or (abs(dy)==1 and dx==0):
                    path[i].append((j,0))
                else:
                    path[i].append((j,1))

d = dijkstra(start,path)
print(-1 if d[goal]==float('inf') else d[goal])
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 1
for a in A:
    if 0 in A:
        ans = 0
        break
    ans *= a
    if ans > 10**18:
        ans = -1
        break
print(ans)

### FIXED CODE ###

def main():
    N =int(input())
    A =list(map(int,input().split()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()
### BUGGY CODE ###

import functools
import operator

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

prod = functools.partial(functools.reduce, operator.mul)
tmp_sum_prod = prod(A[:K])
for i in range(K, N):
    sum_prod = int(tmp_sum_prod * A[i]/A[i-K])
    if sum_prod > tmp_sum_prod:
        print('Yes')
    else:
        print('No')
    tmp_sum_prod = sum_prod


### FIXED CODE ###

import functools
import operator

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

# prod = functools.partial(functools.reduce, operator.mul)
# tmp_sum_prod = prod(A[:K])
for i in range(K, N):
    sum_prod = (A[i]/A[i-K])
    if sum_prod > 1.0:
        print('Yes')
    else:
        print('No')
    tmp_sum_prod = sum_prod
### BUGGY CODE ###

n=int(input())
a=map(int,input().split())
val = 1
for i in a:
	val*=i
if(val>1000000000000000000):
	print(-1)
else:
	print(val)

### FIXED CODE ###

n=int(input())
a=map(int,input().split())
val = 1
exceed = 0
for i in a:
	if(exceed==0 or i==0):
		val*=i
	if(val==0):
		print(0)
		exit(0)
	if(val>1000000000000000000):
		exceed=1
if(exceed==0):
	print(val)
else:
	print(-1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from heapq import merge
from bisect import bisect
def inpl(): return list(map(int, input().split()))

X, Y, Z, K = inpl()
A = inpl()
B = inpl()
C = sorted(inpl(), reverse=True)

AB = sorted([a+b for a in A for b in B])[-K:]
ans = [-1] * K

for c in C:
    if ans[0] > AB[-1] * c:
        break
    tmp = [ab + c for ab in AB]
    ans = list(merge(ans, tmp))[-K:]

print(*ans[::-1], sep="\n")

### FIXED CODE ###

# -*- coding: utf-8 -*-
from heapq import merge
from bisect import bisect
def inpl(): return list(map(int, input().split()))

X, Y, Z, K = inpl()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl(), reverse=True)

AB = [-1] * K
for a in A[::-1]:
    if AB[0] >= B[-1] + a:
        break
    tmp = [a + b for b in B[bisect(B, AB[0]-a):]][-K:]
    AB = list(merge(tmp, AB))[-K:]

ans = [-1] * K

for c in C:
    if ans[0] >= AB[-1] + c:
        break
    tmp = [ab + c for ab in AB[bisect(AB, ans[0]-c):]][-K:]
    ans = list(merge(ans, tmp))[-K:]

print(*ans[::-1], sep="\n")
### BUGGY CODE ###

n = int(input())
s = str(input())
cou = n
lis = []
for i in range(n):
    if i == 0:
        lis.append(s[i+1:n].count("E"))
    else:
        lis.append(s[0:i].count("W")+s[i+1:n].count("E"))
print(min(lis))

### FIXED CODE ###

n = int(input())
lis = [0]
s = str(input())
cou = 0
co  = 0
for i in range(n-1):
    if s[i] == "W":cou += 1
    lis.append(cou)
for k in range(1,n):
    if s[n-(k)] == "E":co += 1
    lis[n-(k+1)] += co
print(min(lis))
### BUGGY CODE ###

from collections import deque
H,W,K = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
sx-=1;sy-=1;gx-=1;gy-=1
Pond = []; INF = float("inf")
for i in range(H):
  temp = str(input());temp = list(temp)
  Pond.append(temp)
#print(Pond)
Q = deque([])
Q.append((sx,sy))
reach = [[INF]*W for _ in range(H)]
reach[sx][sy] = 0
dxdy = [(1,0),(-1,0),(0,1),(0,-1)]
while Q:
  nx,ny = Q.popleft()
  step = K
  for i in range(4):
    for fac in range(1,K+1):
      tx = nx + fac*dxdy[i][0]
      ty = ny + fac*dxdy[i][1]
      #print(i,tx,ty)
      if 0>tx or tx>=H or 0>ty or ty>=W or Pond[tx][ty] == "@": #or reach[tx][ty] != INF:
        #print(i,tx,ty,reach[2][0])
        break #範囲外やハスがあった、到達済みの場合には終了
      #print(i,tx,ty)
      if reach[nx][ny] + 1 > reach[tx][ty]: #もし現時点よりもステップが大きい場合はだめ。
        #同じ場合は向き的に得している場合もあるので残す。
        break
      reach[tx][ty] = reach[nx][ny] + 1
      Q.append((tx,ty))
      if tx == gx and ty == gy:
        print(reach[gx][gy])
        exit()
#print(reach)
#ans = reach[gx][gy]
#if ans == INF:
print(-1)
#else:
#  print(ans)

### FIXED CODE ###

from collections import deque
H,W,K= map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
sx-=1;sy-=1;gx-=1;gy-=1 #0index
Pond = []
for i in range(H):
  temp = str(input())
  temp = list(temp)
  Pond.append(temp)
#print(Pond)
INF = float("inf")
reach = [[INF for _ in range(W)] for _ in range(H)]
reach[sx][sy] = 0
dxdy = [(1,0),(-1,0),(0,1),(0,-1)]
Q = deque([(sx,sy)])
while Q:
  x,y = Q.popleft()
  #print(x,y)
  #step = reach[x][y]
  for j in range(4):
    for i in range(1,K+1):
      fac = i
      nx = x+fac*dxdy[j][0]
      ny = y+fac*dxdy[j][1]
      #print(nx,ny)
      if nx<0 or nx>=H or ny<0 or ny>= W or Pond[nx][ny] == "@":
        break
      if reach[x][y]+1 > reach[nx][ny]: #すでに余裕をもって到達済み
        break
      if reach[x][y]+1 < reach[nx][ny]:
        reach[nx][ny] = min(reach[x][y]+1,reach[nx][ny])
        Q.append((nx,ny))
      if nx == gx and ny == gy:
        #print(reach)
        print(reach[nx][ny])
        exit()
print(-1)
### BUGGY CODE ###

n = int(input())
li = list(map(int,input().split()))
ans = 0

import math
import bisect
import collections
c = collections.Counter(li)
li = list(set(li))
li.sort()
while len(li)>0:
    ba = li.pop(-1)
    if c[ba]>1:
        continue
    s_ba = ba//2+1
    index = bisect.bisect_left(li, s_ba)
    tmp_li = li[:index+1]
    #print(ba,tmp_li)
    for tt in tmp_li:
        if ba%tt == 0:
            break
    else:
        ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
li = list(map(int,input().split()))
ans = 0
cnt_li = [0]*(10**6+1)

import math
import bisect
import collections
c = collections.Counter(li)
li = list(set(li))
li.sort()

for l in li:
    for x in range(2,10**7):
        if x*l > (10**6):
            break
        else:
            cnt_li[x*l] += 1


while len(li)>0:
    ba = li.pop(-1)
    if c[ba]>1:
        continue
    if cnt_li[ba] == 0:
        ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(1, 2**N):
    comb = list(map(int, bin(i)[2:].zfill(N)))
    X, Y = 0, 0
    for i, c in enumerate(comb):
        if c == 1:
            X += V[i]
            Y += C[i]
    ans = max(ans, X-Y)

print(ans)

### FIXED CODE ###

N = int(input())
values = list(map(int, input().split()))
costs = list(map(int, input().split()))
gains = [values[i] - costs[i] for i in range(N) if values[i] - costs[i] > 0]
print(max(sum(gains), 0))
### BUGGY CODE ###

import math
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [math.inf for i in range(number)]
res[0] =0 
test = [math.inf for k in range(jump)]
test[0] = 0

for i in range(number):
    for j in range(1,jump+1):
        if i-j < 0:break
        cost = abs(scaffolding[i]-scaffolding[i-j])
        test[j-1] = res[i-j] + cost
    
    res[i] = min(test)
    

print(res[number-1])




### FIXED CODE ###

import math
import sys
input = sys.stdin.readline
number, jump =input().rstrip().split()
number = int(number)
jump = int(jump)
scaffolding = input().rstrip().split()
scaffolding = list(map(int, scaffolding))
res = [0 for i in range(number)]
res[1] = abs(scaffolding[1]-scaffolding[0])
#test = [math.inf for k in range(jump)]
#test[0] = 0

for i in range(2, number):
    h=max(0,i-jump)
    res[i]=min(res[k]+abs(scaffolding[i]-scaffolding[k]) for k in range(h,i))   
    #res[i] = min(test)
    

print(res[number-1])
### BUGGY CODE ###

n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
    ci, si, fi = map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)
for i in range(n - 1):
    time = s[i] + c[i]
    for j in range(i + 1, n - 1):
        if time % f[j] == 0 and time >= s[j]:
            time += c[j]
        else:
            while time % f[j] != 0 or s[j] > time:
                time += 1
            time += c[j]
    print(time)
print(0)

### FIXED CODE ###

n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
    ci, si, fi = map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)
#c, s, f
for i in range(n - 1):
    time = s[i] + c[i]
    for j in range(i + 1, n - 1):
        if time < s[j]:
            time = s[j] + c[j]
        elif time % f[j] != 0:
            time += f[j] - time % f[j] + c[j]
        else:
            time += c[j]
    print(time)
print(0)
### BUGGY CODE ###

N = int(input())

d = [[int((str(x))[0]),x % 10] for x in range(1,N + 1)] 
a = [[x % 10,int((str(x))[0])] for x in range(1,N + 1)]

count = 0
for i in range(0,N):
    for j in range(0,N):
        if d[i] == a[j]:
            count += 1
print(count)

### FIXED CODE ###

N = int(input())
t = [[0] * 10 for _ in range(10)]
for i in range(1, N + 1):
    s = str(i)
    t[int(s[0])][int(s[-1])] += 1
result = 0
for i in range(1, 10):
    for j in range(1, 10):
        result += t[i][j] * t[j][i]
print(result)
### BUGGY CODE ###

import sys
from heapq import heappop, heappush
import numpy as np

from numba import njit, int64


@njit(int64(int64, int64[:]), cache=True)
def solve(n, ppp):
    n2 = n + 2
    seats = [-1] * (n2 * n2)
    is_seated = [False] * (n2 * n2)
    for i in range(n):
        ud = min(i, n - 1 - i)
        for j in range(n):
            ij = (i + 1) * n2 + j + 1
            seats[ij] = min(ud, j, n - 1 - j)
            is_seated[ij] = True

    ans = 0

    for p in ppp:
        i, j = divmod(p - 1, n)
        i = (i + 1) * n2 + j + 1
        res = seats[i]
        ans += res
        is_seated[i] = False

        q = [(res, i)]
        while q:
            val, j = heappop(q)
            seats[j] = val
            if is_seated[j]:
                val += 1

            nj = j - n2
            if seats[nj] > val:
                heappush(q, (val, nj))
            nj = j - 1
            if seats[nj] > val:
                heappush(q, (val, nj))
            nj = j + 1
            if seats[nj] > val:
                heappush(q, (val, nj))
            nj = j + n2
            if seats[nj] > val:
                heappush(q, (val, nj))

    return ans


n = int(sys.stdin.buffer.readline())
ppp = np.array(list(map(int, sys.stdin.buffer.read().split())), dtype=np.int64)
print(solve(n, ppp))

# solve.inspect_types()
# bfs.inspect_types()


### FIXED CODE ###

import sys
import numpy as np

from numba import njit


@njit('i4(i4,i4[:])', cache=True)
def solve(n, ppp):
    n2 = n + 2
    nsq = n2 * n2
    seats = np.zeros(nsq, dtype=np.int16)
    is_seated = np.zeros(nsq, dtype=np.int8)
    for i in range(n):
        ud = min(i, n - 1 - i)
        ri = (i + 1) * n2
        for j in range(n):
            ij = ri + j + 1
            seats[ij] = min(ud, j, n - 1 - j)
            is_seated[ij] = 1

    MOVES = np.array([-n2, -1, 1, n2], dtype=np.int32)

    ans = 0

    for pi in range(n * n):
        i, j = divmod(ppp[pi], n)
        i = (i + 1) * n2 + j + 1
        res = seats[i]
        ans += res
        is_seated[i] = 0

        q = []
        for mi in range(4):
            ni = i + MOVES[mi]
            if seats[ni] > res:
                seats[ni] = res
                q.append(ni)

        while q:
            j = q.pop()
            # print(val, j, seats[j], l, r)
            val = seats[j]

            if is_seated[j]:
                val += 1
            for mi in range(4):
                nj = j + MOVES[mi]
                if seats[nj] > val:
                    seats[nj] = val
                    q.append(nj)

        # print(ppp[pi] + 1, i, ans)
        # print(seats.reshape((n2, n2)))
        # print(is_seated.reshape((n2, n2)))

    return ans


n = int(sys.stdin.buffer.readline())
ppp = np.array(list(map(int, sys.stdin.buffer.read().split())), dtype=np.int32) - 1

# n = 20
# np.random.seed(seed=32)
# ppp = np.random.permutation(n * n).astype(np.int32)
# print(ppp)

print(solve(n, ppp))
### BUGGY CODE ###

import copy
def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    c = [[None]*w for _ in range(h)]
    for i in reversed(range(h)):
        for j in reversed(range(w)):
            c[i][j] = abs(a[i][j] - b[i][j])
            if i < h-1:
                c[i][j] += c[i+1][j]
            if j < w-1:
                c[i][j] += c[i][j+1]
    dp = [set() for i in range(w)]
    dp[0].add(a[0][0] - b[0][0])
    for j in range(1, w):
        x = a[0][j] - b[0][j]
        for v in dp[j-1]:
            dp[j].add(v + x)
            dp[j].add(v - x)
    for i in range(1, h):
#        print(dp)
        for j in range(w):
            x = a[i][j] - b[i][j]
            if j == 0:
                buf = copy.deepcopy(dp[j])
                dp[j].clear()
                for v in buf:
                    dp[j].add(v + x)
                    dp[j].add(v - x)
            else:
                buf = dp[j-1] | dp[j]
                dp[j].clear()
                for v in buf:
                    dp[j].add(v + x)
                    dp[j].add(v - x)
    ans = float("inf")
#    print(dp)
    for v in dp[w-1]:
        ans = min(ans, abs(v))
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
def main():
    h, w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    n = 80*(80+80) + 10
    m = n//2
    dp = [[None]*w for i in range(h)]
    for i in range(h):
        for j in range(w):
            dp[i][j] = np.zeros(n, np.bool)
    dp[0][0][m+abs(a[0][0] - b[0][0])] = True
    dp[0][0][m-abs(a[0][0] - b[0][0])] = True
    for i in range(h):
        for j in range(w):
            x = abs(a[i][j] - b[i][j])
            if 0 < i and 0 < h:
                dp[i][j][x:] |= dp[i-1][j][:n-x]
                dp[i][j][:n-x] |= dp[i-1][j][x:]
                dp[i][j][x:] |= dp[i][j-1][:n-x]
                dp[i][j][:n-x] |= dp[i][j-1][x:]
            elif 0 < i:
                dp[i][j][x:] |= dp[i-1][j][:n-x]
                dp[i][j][:n-x] |= dp[i-1][j][x:]
            elif 0 < j:
                dp[i][j][x:] |= dp[i][j-1][:n-x]
                dp[i][j][:n-x] |= dp[i][j-1][x:]
    ans = float("inf")
    for i in range(m-80-1, m+80+2):
        if dp[h-1][w-1][i]:
            ans = min(ans, abs(m-i))
    print(ans)

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

import math
n,m=map(int,input().split())
mod=10**9+7
if 2<=abs(n-m):
    print(0)
elif abs(n-m)==1:
    print(math.factorial(n)*math.factorial(m)%mod)
elif n==m:
    print(2*math.factorial(n)*math.factorial(m))

### FIXED CODE ###

import math
mod=10**9+7
n,m=map(int,input().split())
ans=0
if abs(n-m)==0:
    ans=math.factorial(n)*math.factorial(m)*2
elif abs(n-m)==1:
    ans=math.factorial(n)*math.factorial(m)
else:
    ans=0
ans=ans%mod
print(ans)
### BUGGY CODE ###

S = list(map(int,list(input())))

MOD = 2019
T = []
S.reverse()
cnt = 0
temp = 0
for i in S:
    temp += i*10**cnt % MOD
    temp %= MOD
    T.append(temp)
    cnt += 1

T.reverse()
T.append(0)

ans = [0]*2019

for i in T:
    ans[i-1] += 1

ans2 = 0
for i in ans:
    ans2 += i*(i-1)//2
print(ans2)

### FIXED CODE ###

S = list(input())

MOD = 2019
S.reverse()
cnt = 1
temp = 0
ans = [0]*2019
for i in S:
    temp += int(i)*cnt % MOD
    temp %= MOD
    ans[temp] += 1
    cnt *= 10
    cnt %= MOD

ans[0] += 1

ans2 = 0
for i in ans:
    ans2 += i*(i-1)//2
print(ans2)
### BUGGY CODE ###

import sys
from collections import deque


H,W=map(int, raw_input().split())
A=[ list( sys.stdin.readline().strip())  for i in range(H) ]


D=[ (-1,0),(1,0),(0,1),(0,-1) ]
K=[ [ float("inf") for j in range(W) ] for i in range(H)  ]  #Kyori

def bfs(h,w):
	V=[ [ 0 for j in range(W) ] for i in range(H)  ]
	q=deque()
	V[h][w]=1
	K[h][w]=0
	q.append( (h,w) )
	while q:
		h, w=q.popleft()	# newh , neww
		for dx,dy in D:
			if 0<=h+dx<H and 0<=w+dy<W:
				if A[h+dx][w+dy]=="." and V[h+dx][w+dy]==0:
					V[h+dx][w+dy]=1
					K[h+dx][w+dy]=min( K[h+dx][w+dy], K[h][w]+1 )
					q.append( (h+dx,w+dy) )	


for i in range(H):
	for j in range(W):
		if A[i][j]=="#":
			bfs(i,j)


ans=0
for i in range(H):
	ans=max(ans , max(K[i]))

print ans

### FIXED CODE ###

import sys
from collections import deque

H,W=map(int, raw_input().split())
A=[ list( sys.stdin.readline().strip())  for i in range(H) ]


D=[ (-1,0),(1,0),(0,1),(0,-1) ]
K=[ [ float("inf") for j in range(W) ] for i in range(H)  ]  #Kyori

q=deque()

for i in range(H):
	for j in range(W):
		if A[i][j]=="#":
			q.append( (i,j) )
			K[i][j]=0


while q:
	h,w=q.popleft()
	for dx,dy in D:
		if 0<=h+dx<H and 0<=w+dy<W and K[h+dx][w+dy]>K[h][w]+1:
				K[h+dx][w+dy]=K[h][w]+1
				q.append( (h+dx,w+dy) )	

ans=0
for x in K:
	ans=max(ans, max(x) )
print ans
### BUGGY CODE ###

s = input()
q = int(input())
for _ in range(q):
    l = input()
    if l == "1":
        s = s[::-1]
    else:
        t, f, c = l.split()
        if f == "1":
            s = c + s
        else:
            s += c
print(s)

### FIXED CODE ###

#!/usr/bin/env python3
s, _, *q = open(0)
g = ""
s = s.strip()
for q in q:
  q = q.strip().split()
  if q[0] == "1":
    g, s = s, g
  else:
    if q[1] == "1":
      g += q[2]
    else:
      s += q[2]
print(g[::-1] + s)
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
def sub(ii):
    dp = 1
    mask = (1<<(k+1)) - 1
    for i in range(n):
        if i==ii:
            continue
        dp |= dp<<a[i]
        dp &= mask
#         for j in range(k-1, a[i]-1, -1):
#             dp[j] += dp[j-a[i]]
    val = max(i for i in range(k) if (dp>>i)&1)
    return val+a[ii]>=k
if sub(0):
    ans = 0
elif not sub(n-1):
    ans = n
else:
    l = 0
    r = n-1
    while l<r-1:
        m = (l+r)//2
        if sub(m):
            r = m
        else:
            l = m
    ans = l+1
print(ans)

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
a = list(map(lambda x: min(int(x), k+1), input().split()))
a.sort()
mask = (1<<(k+1)) - 1
def sub(ii):
    dp = 1
    for i in range(n):
        if i==ii:
            continue
        dp |= (dp<<a[i]) & mask
#         for j in range(k-1, a[i]-1, -1):
#             dp[j] += dp[j-a[i]]
    val = max(i for i in range(k) if (dp>>i)&1)
    return val+a[ii]>=k
if sub(0):
    ans = 0
elif not sub(n-1):
    ans = n
else:
    l = 0
    r = n-1
    while l<r-1:
        m = (l+r)//2
        if sub(m):
            r = m
        else:
            l = m
    ans = l+1
print(ans)
### BUGGY CODE ###

from bisect import bisect_left

INF = float("inf")


def main():
    A, B, Q = map(int, input().split())
    S = [-INF] + [int(input()) for _ in range(A)] + [INF]
    T = [-INF] + [int(input()) for _ in range(B)] + [INF]
    for i in range(Q):
        x = int(input())
        l1 = bisect_left(S, x)
        l2 = bisect_left(T, x)
        tmp = INF
        for s in (S[l1-1], S[l1]):
            for t in (T[l2-1], T[l2]):
                tmp = min(tmp, abs(s-t) + abs(x-s))
                tmp = min(tmp, abs(s-t) + abs(x-t))
        print(tmp)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from bisect import bisect_left

INF = 10**12


def main():
    A, B, Q = map(int, input().split())
    S = [-INF] + [int(input()) for _ in range(A)] + [INF]
    T = [-INF] + [int(input()) for _ in range(B)] + [INF]
    for _ in range(Q):
        x = int(input())
        l1 = bisect_left(S, x)
        l2 = bisect_left(T, x)
        tmp = INF
        for s in (S[l1-1], S[l1]):
            for t in (T[l2-1], T[l2]):
                tmp = min(tmp, abs(s-t) + abs(x-s))
                tmp = min(tmp, abs(s-t) + abs(x-t))
        print(tmp)


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

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[]
for j in range(n-k+1):
  x=1  
  for i in range(j,j+k):
    x*=a[i]
  b.append(x)

for m in range(len(b)-1):
  if b[m]<b[m+1]:
    print("Yes")
  else:
    print("No")


### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n-k):
  if a[i]<a[i+k]:
    print('Yes')
  else:
    print('No')