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

import sys
input = sys.stdin.readline
def main():
  h,w=map(int,input().split())
  a=[input() for _ in range(h)]
  seen=[[-1]*w for _ in range(h)]
  from collections import deque
  todo=deque([])
  for hi,ai in enumerate(a):
    for wj,aij in enumerate(ai):
      if aij=='#':
        seen[hi][wj]=0
        todo.append((hi,wj,0))
  while len(todo)>0:
    hi,wi,i=todo.popleft()
    if hi>0 and seen[hi-1][wi]==-1:
      todo.append((hi-1,wi,i+1))
      seen[hi-1][wi]=i+1
    if hi<h-1 and seen[hi+1][wi]==-1:
      todo.append((hi+1,wi,i+1))
      seen[hi+1][wi]=i+1
    if wi>0 and seen[hi][wi-1]==-1:
      todo.append((hi,wi-1,i+1))
      seen[hi][wi-1]=i+1
    if wi<w-1 and seen[hi][wi+1]==-1:
      todo.append((hi,wi+1,i+1))
      seen[hi][wi+1]=i+1
  print(i)
if __name__=='__main__':
  main()

### FIXED CODE ###

h,w=map(int,input().split())
a=[input() for _ in range(h)]
seen=[[-1]*w for _ in range(h)]
from collections import deque
todo=deque([])
for hi in range(h):
  for wi in range(w):
    if a[hi][wi]=='#':
      seen[hi][wi]=0
      todo.append((hi,wi,0))
while len(todo)>0:
  hi,wi,i=todo.popleft()
  if hi>0 and seen[hi-1][wi]==-1:
    todo.append((hi-1,wi,i+1))
    seen[hi-1][wi]=i+1
  if hi<h-1 and seen[hi+1][wi]==-1:
    todo.append((hi+1,wi,i+1))
    seen[hi+1][wi]=i+1
  if wi>0 and seen[hi][wi-1]==-1:
    todo.append((hi,wi-1,i+1))
    seen[hi][wi-1]=i+1
  if wi<w-1 and seen[hi][wi+1]==-1:
    todo.append((hi,wi+1,i+1))
    seen[hi][wi+1]=i+1
print(max([max(seeni) for seeni in seen]))
### BUGGY CODE ###

import sys

input = sys.stdin.readline


def dfs(H, W, D, A, mp):
    position = [None] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i][i + D] = abs(x - w) + abs(y - h)

    for i in range(1, H * W + 1 - 2 * D):
        for j in range(i + 2 * D, H * W + 1):
            mp[i][j] = mp[i][j - D] + mp[j - D][j]


def main():
    H, W, D = map(int, input().split())
    A = [None] * H
    for i in range(H):
        A[i] = list(map(int, input().split()))
    Q = int(input())
    L = [0] * Q
    R = [0] * Q
    for i in range(Q):
        L[i], R[i] = map(int, input().split())

    mp = [[0] * (H * W + 1) for _ in range(H * W + 1)]
    dfs(H, W, D, A, mp)

    ans = [mp[l][r] for l, r in zip(L, R)]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("void(i8,i8,i8,i8[:,:],i8,i8[:,:],i8[:])", cache=True)
def dfs(H, W, D, A, Q, LR, ans):
    position = [(-1, -1)] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = np.zeros(shape=(H * W + 1), dtype=np.int64)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = np.cumsum(mp[d::D])

    for i in range(Q):
        l, r = LR[i]
        ans[i] = mp[r] - mp[l]


def main():
    H, W, D = map(int, input().split())
    A = np.zeros(shape=(H, W), dtype=np.int64)
    for i in range(H):
        A[i] = tuple(map(int, input().split()))
    Q = int(input())
    LR = np.zeros(shape=(Q, 2), dtype=np.int64)
    for i in range(Q):
        LR[i] = tuple(map(int, input().split()))

    ans = np.zeros(shape=Q, dtype=np.int64)
    dfs(H, W, D, A, Q, LR, ans)

    print("\n".join(map(str, ans)))


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

N = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()
Ans = []
d = 0
while len(Ans) < 2:
  c = A.count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
print(Ans[0]*Ans[1])

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = (A[d:d+4]).count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!

import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

from itertools import accumulate

n = int(input())
a = [int(i) for i in readline().split()]

res = [0]*(n+1)
for i in a: res[i] += 1

c = []
for i in res:
    if i > 0: c.append(i)
c.sort()#reverse=True)

l = len(c)
#print(c)

acc = list(accumulate(c))


memo = {}
def f(m,k):#最初のm個, kずつ
    if m == 0: return 0
    if m < k: return 0
    if (m,k) in memo:
        return memo[(m,k)]
    z = 0
    if acc[m-1]//k >= c[m-1]:
        z = acc[m-1]//k
    else:
        z = f(m-1,k-1)
    memo[(m,k)] = z
    return z
    
for i in range(1,n+1):
    print(f(l,i))











### FIXED CODE ###

# coding: utf-8
# Your code here!
def f(m,k):#最初のm個, kずつ
    if m == 0: return 0
    if m < k: return 0
#    if (m,k) in memo:
#        return memo[(m,k)]
    z = 0
    if acc[m]//k >= c[m]:
        return acc[m]//k
    else:
        return f(m-1,k-1)


import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

from itertools import accumulate

n = int(input())
a = [int(i) for i in readline().split()]

res = [0]*(n+1)
for i in a: res[i] += 1

c = [0]
for i in res:
    if i > 0: c.append(i)
c.sort()#reverse=True)

l = len(c)-1
#print(c)
acc = list(accumulate(c))

#print(acc,c)
res = [n]+[acc[m]//c[m] for m in range(1,l+1)]


#print(l,res)


m = l
for k in range(1,n+1):
    k -= l-m
    if res[m] >= k:
        print(acc[m]//k)
    else:
#        print(k,m)
        while res[m] < k:
            m -= 1
            k -= 1
        print(acc[m]//(k))
### BUGGY CODE ###

n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
dp = [float() for e in range(n)]

dp[0] = 0
dp[1] = abs(h[1]-h[0])


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

print(dp[-1])

### FIXED CODE ###

n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]

import numpy as np

h = np.array(h)
dp = np.zeros(n)

dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2,n):
    l =i-k if i-k >= 0 else 0
    dp[i] = np.min(dp[l:i]+np.abs(h[i]-h[l:i]))


print(int(dp[-1]))
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
    
h, w = MAP()
s = [STR() for _ in range(h)]
arr = [[inf for _ in range(w)] for _ in range(h)]
arr[0][0] = 0
que = deque([[0, 0]])
dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]
while len(que):
    y, x = map(int, que.popleft())
    if s[y][x] == '.':
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if 0 <= ny < h and 0 <= nx < w:
                tmp = arr[y][x]
                arr[y][x] = min(arr[y][x], arr[ny][nx] + 1)
                if arr[ny][nx] >= inf:
                    que.append([ny, nx])
    if y == h - 1 and x == w - 1:
        break
if arr[h - 1][w - 1] >= inf:
    print(-1)
    exit()
ss = 0
for i in range(h):
    ss += s[i].count('.')
print(ss - arr[h - 1][w - 1] - 1)


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

h, w = MAP()
s = [STR() for _ in range(h)]
arr = [[inf for _ in range(w)] for _ in range(h)]
arr[0][0] = 0
que = deque([[0, 0]])
dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]
while len(que):
    y, x = map(int, que.popleft())
    for i in range(4):
        ny = y + dy[i]
        nx = x + dx[i]
        if 0 <= ny < h and 0 <= nx < w:
            tmp = arr[y][x]
            arr[y][x] = min(arr[y][x], arr[ny][nx] + 1)
            if arr[ny][nx] >= inf and s[ny][nx] == '.' and not [ny, nx] in que:
                que.append([ny, nx])
    if y == h - 1 and x == w - 1:
        break
if arr[h - 1][w - 1] >= inf:
    print(-1)
    exit()
ss = 0
for i in range(h):
    ss += s[i].count('.')
print(ss - arr[h - 1][w - 1] - 1)
### BUGGY CODE ###

def calc(i, k):
    ans_list = [i]
    count = 1
    i = a[i]
    while (i not in ans_list) & (count < n):
        ans_list.append(i)
        count += 1
        i = a[i]
    index = ans_list.index(i)
    ans_list.append(i)
    return count, ans_list

n, k = map(int, input().split())
a = [int(i) - 1 for i in input().split()]

count, ans_list = calc(0, k)
if count < k:
    index = ans_list.index(ans_list[-1])
    k = k - index
    ans_list = ans_list[index + 1:]
    print(ans_list[k % len(ans_list) - 1] + 1)
else:
    print(ans_list[k] + 1)

### FIXED CODE ###

n, k = map(int, input().split())
a = [int(i) - 1 for i in input().split()]
visit = {0}
tmp = 0
a_list = [0]
ans = True
for i in range(k):
    tmp = a[tmp]
    if tmp in visit:
        left = a_list.index(tmp)
        ans = False
        print(a_list[left + (k - left) % (i + 1 - left)] + 1)
        break
    else:
        visit.add(tmp)
        a_list.append(tmp)
if ans:
    print(tmp + 1)
### BUGGY CODE ###

k, s = map(int, input().split())

ans = sum([x + y + z == s for x in range(k + 1) for y in range(k + 1) for z in range(k + 1)])
print(ans)

### FIXED CODE ###

k, s = map(int, input().split())

counter = 0
for z in range(0, k+1):
  if 2 * k < s - z:
    continue
  for y in range(0, k+1):
    if k + y + z < s:
      continue
    elif   s - y - z < 0:
      break
    else:
      counter += 1
print(counter)
### BUGGY CODE ###

n = int(input())
A = list(map(int, input().split()))
b = []

for a in A:
    b.append(a)
    b.reverse()
print(*b)

### FIXED CODE ###

from collections import deque
def main():
    n = int(input())
    a = [0] + list(map(int, input().split()))
    b = deque(maxlen=n+1)
    for i in range(1,n+1):
        if (i % 2 == 0 and n % 2 == 0 ) or (i % 2 != 0 and n % 2 != 0 ):
            b.appendleft(a[i])
        else:
            b.append(a[i])

    print(*b)

main()
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

for b, c in BC:
    A.sort()
    for i in range(b):
        if A[i] < c:
            A[i] = c
print(sum(A))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]
BC = sorted(BC, key=lambda x: x[1])
A.sort()
i = 0
for b, c in BC[::-1]:
    for _ in range(b):
        if i == N:
            break
        if c > A[i]:
            A[i] = c
            i += 1
        else:
            break

print(sum(A))
### BUGGY CODE ###

from collections import Counter
n = int(input())
IN = [input() for _ in range(n)]
S = []
for i in IN:
    S.append(''.join(sorted(i)))

ans = 0
for i in range(1, n):
    for j in range(i):
        if S[i] == S[j]:
            ans += 1

print(ans)

### FIXED CODE ###

n = int(input())
S = [input() for _ in range(n)]

table = {}
ans = 0
for i in S:
    s = ''.join(sorted(i))
    if s not in table:
        table[s] = 0
    else:
        table[s] += 1
        ans += table[s]
print(ans)
### BUGGY CODE ###

n = int(input())
a =[int(input()) for _ in range(n)]

for i in range(len(a)):
    tmp = a.pop(i)
    print(max(a))
    a.insert(i, tmp)



### FIXED CODE ###

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

max1 = max(a)
max2 = sorted(a)[-2]

if a.count(max1) >= 2:
    for i in range(n):
        print(max1)
elif a.count(max1) == 1:
    for i in range(n):
        if a[i] == max1:
            print(max2)
        else:
            print(max1)
### BUGGY CODE ###

n,m=map(int,input().split())
A=[]
for i in range(m):
    A.append(int(input()))

x=[0]*(n+1)
x[0]=1
if 1 in A:
    x[1]=0
else:
    x[1]=1

for j in range(2,n+1):
    if j in A:
        x[j]=0
    else:
        x[j]=x[j-1]+x[j-2]
        x[j]=x[j]%1000000007

print(x[n])
    

### FIXED CODE ###

n,m=map(int,input().split())
A=set(int(input()) for i in range(m))
 
x=[0]*(n+1)
x[0]=1
if 1 in A:
    x[1]=0
else:
    x[1]=1
 
for j in range(2,n+1):
    if j in A:
        x[j]=0
    else:
        x[j]=(x[j-1]+x[j-2])%(10**9+7)
        
 
print(x[n])
### BUGGY CODE ###

from collections import deque
N,M = map(int,input().split())
l = [[] for _ in range(N+1)]
for _ in range(M):
  a,b = map(int,input().split())
  l[a].append(b)
  l[b].append(a)

ans = 'No'
st = deque([1])
check = [0]*(N+1)
check[1] = 1
mark = [0]*(N+1)

while st:
  s = st.popleft()
  for t in l[s]:
    if check[t] == 0:
      mark[t] = s
      check[t] = 1
      st.append(t)
  if sum(check) == N:
    ans = 'Yes'
    break

print(ans)
if ans == 'Yes':
  for i in range(2,N+1):
    print(mark[i])

### FIXED CODE ###

N,M = map(int,input().split())
AB = [[] for _ in range(N)]
ans = [0]*N
for _ in range(M):
  a,b = map(int,input().split())
  AB[a-1].append(b-1)
  AB[b-1].append(a-1)

from collections import deque

node = 0
q = deque([0])

check = [0]*N
check[0] = 1
while len(q) > 0:
  node = q.popleft()
  for i in AB[node]:
    if check[i] == 0:
      q.append(i)
      check[i] = 1
      ans[i] = node
print("Yes")
for i in range(1,N):
  print(ans[i]+1)
### BUGGY CODE ###

n , m = map(int, input().split())
p = list(map(int,input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]


uf = UnionFind(n)

for i in range(m):
    x , y = map(int, input().split())
    x-=1
    y-=1
    uf.union(x,y)
ans = 0
for i in range(n):
    if i in uf.members(p[i]-1):
        ans+=1
print(ans)


### FIXED CODE ###

n , m = map(int, input().split())
p = list(map(int,input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)


uf = UnionFind(n)

for i in range(m):
    x , y = map(int, input().split())
    x-=1
    y-=1
    uf.union(x,y)
ans = 0
for i in range(n):
    if uf.same(i,p[i]-1):
        ans+=1
print(ans)
### BUGGY CODE ###

def training():
	N = int(input())

	A = [0]

	for i in range(N):
		A.append(int(input()))

	counter = 1
	index = 1
	judge = [1]
	if A[index] == 2:
		print(counter)
		return
	counter += 1
	index = A[index]
	while True:
		if A[index] in judge:
			print("-1")
			return
		if A[index] == 2:
			print(counter)
			return
		counter += 1
		judge.append(A[index])
		index = A[index]
	

training()
	

### FIXED CODE ###

def training():
	N = int(input())

	A = [0]

	for i in range(N):
		A.append(int(input()))

	counter = 1
	index = 1
	#judge = [1]
	if A[index] == 2:
		print(counter)
		return
	counter += 1
	index = A[index]
	for i in range(N):
		#if A[index] in judge:
			#print("-1")
			#return
		if A[index] == 2:
			print(counter)
			return
		counter += 1
		#judge.append(A[index])
		index = A[index]
	print("-1")
	

training()
### BUGGY CODE ###

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

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]

value = [[-1 for j in range(W + 1)] for i in range(N + 1)]

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

ans = max(max(value))
print(ans)


### FIXED CODE ###

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

import sys
input = sys.stdin.readline

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(N)]

value = [[-1 for j in range(W + 1)] for i in range(N + 1)]

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

ans = max(value[N])
print(ans)
### BUGGY CODE ###

A, B, N = map(int, input().split())
answer = 0
for i in range(min(B,N+1)):
    mae = (A*i)//B
    usiro = A*(i//B)

    l = mae-usiro
    if l > answer:
        answer = l
print(answer)

### FIXED CODE ###

A, B, N = map(int, input().split())
answer = 0
if B > N:
    mae = (A*N)//B
    usiro = A*(N//B)
    l = mae-usiro
else:
    i = (B-1)
    mae = (A*i)//B
    usiro = A*(i//B)
    l = mae-usiro
print(l)
### BUGGY CODE ###

def f(d):
    ans = 0
    if d[1]==0 and d[2]==0 and d[3]==0:
        return ans
    try:
        return stored[(d[1],d[2],d[3])]
    except:
        pass
    ans += (d[0]+d[1]+d[2]+d[3])/(d[1]+d[2]+d[3])
    if d[1]:
        x = d[1]/(d[1]+d[2]+d[3])
        ans += x*f([d[0]+1,d[1]-1,d[2],d[3]])
    if d[2]:
        x = d[2]/(d[1]+d[2]+d[3])
        ans += x*f([d[0],d[1]+1,d[2]-1,d[3]])
    if d[3]:
        x = d[3]/(d[1]+d[2]+d[3])
        ans += x*f([d[0],d[1],d[2]+1,d[3]-1])
    stored[(d[1],d[2],d[3])] = ans
    return ans


n = int(input())
a = list(map(int,input().split()))
d = [0 for i in range(4)]
stored = {}

for i in a:
    d[i] +=1

ans = 0
print(f(d))

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
d = [0 for i in range(3)]
dp = [[[0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)] 
for i in a:
    d[i-1] +=1
for k in range(n+1):
    for j in range(n+1):
        for i in range(n+1):
            if i+j+k==0 or i+j+k>n:
                continue
            ans = n/(i+j+k)
            x = i/(i+j+k)
            if x:
                ans += x*dp[k][j][i-1]
            x = j/(i+j+k)
            if x:
                ans += x*dp[k][j-1][i+1]
            x = k/(i+j+k)
            if x:
                ans += x*dp[k-1][j+1][i]
            dp[k][j][i] = ans
print(dp[d[2]][d[1]][d[0]])
### BUGGY CODE ###

a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
flg = 0

for _ in range(t):
    if a < b:
        if v <= w:
            break
        if a+v >= b+w:
            flg = 1
            break
        a = a+v
        b= b+w
    else:
        if v <= w:
            break
        if a-v <= b-w:
            flg = 1
            break
        a = a-v
        b=b-w
        
if flg == 0:
    print("NO")
else:
    print("YES")

### FIXED CODE ###

import sys
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

if v<=w:
    print("NO")
    sys.exit()

if a<b:
    if a+t*v>=b+t*w:
        print("YES")
    else:
        print("NO")
else:
    if a-t*v<=b-t*w:
        print("YES")
    else:
        print("NO")
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
B = [0]*N

for i in range(N):
    B[i] += K - Q + A.count(i+1)

#for i in range(N):
    if B[i] > 0:
        print("Yes")
    else:
        print("No")



### FIXED CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
B = [K-Q]*N

for i in range(Q):
    B[A[i]-1] += 1
    
for i in range(N):
#if A.count(i+1) > S :
#      B[i] += S + A.count(i+1)

    if B[i] > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

h,w,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
lis = [[0,0] for i in range(h * w)]
for i in range(h):
    for j in range(w):
        lis[a[i][j]-1] = [i,j]
q = int(input())
for _ in range(q):
    ans = 0
    now,want = map(int,input().split())
    now-=1
    want-=1
    while now != want:
        ans += abs(lis[now][0]-lis[now+d][0])+abs(lis[now][1]-lis[now+d][1])
        now += d
    print(ans)

### FIXED CODE ###

import math
h,w,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
lis = [[0,0] for i in range(h * w)]
num = [[0] * math.ceil((h * w) // d + 1) for i in range(d)]

for i in range(h):
    for j in range(w):
        lis[a[i][j]-1] = [i,j]

for i in range(h * w-d):
    num[i%d][i//d+1] = num[i%d][i//d]+abs(lis[i][0]-lis[i+d][0])+abs(lis[i][1]-lis[i+d][1])

q = int(input())
for _ in range(q):
    now,goal = map(int,input().split())
    if now % d == 0:
        print(num[now%d-1][(goal-now%d)//d-1]-num[now%d-1][(now-now%d)//d-1])
    else:
        print(num[now%d-1][(goal-now%d)//d]-num[now%d-1][(now-now%d)//d])
### BUGGY CODE ###

#%%
import bisect

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

ans_list = []
for i in range(n):
    tmp = bisect.bisect_left(ans_list, a[i])
    #print(tmp)
    if tmp == 0:
        ans_list.insert(0, a[i])
    else:
        ans_list[tmp-1] = a[i]
    #print(ans_list)
print(len(ans_list))

    


### FIXED CODE ###

#%%
import bisect

n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

ans_list = [-1] * n
for i in range(n):
    tmp = bisect.bisect_left(ans_list, a[i])
    #print(tmp)
    if tmp == 0:
        ans_list.insert(0, a[i])
    else:
        ans_list[tmp-1] = a[i]
    #print(ans_list)

ans = 0
for i in range(n):
    if ans_list[i] != -1:
        ans += 1
print(ans)
### BUGGY CODE ###

import numpy as np
N, M = map(int, input().split())

X = []

i = 0
while i < N:
    X.append(list(map(int, input().split())))
    i += 1

X = np.asarray(X)

X_ind = np.argsort(X[:,1], axis=0)
X = X[X_ind]
# print(X)
least = 1
p = 0
while least <= M:
    # print(least)
    best_index = -1
    best_s = 0
    for i in range(X.shape[0]):
        target = X[i]
        if least >= target[0] and best_s <= target[1]:
            best_index = i
            best_s = target[1]
    # print(target)
    p += best_s
    if best_index >= 0:
        X = np.delete(X, best_index, axis=0)
    least += 1

print(p)


### FIXED CODE ###

from heapq import heappush,heappop
N, M = map(int, input().split())

X = []

for _ in range(N):
    a, b = map(int, input().split())
    if a <= M:
        X.append((a,b))


X = sorted(X, key=lambda x:(x[0], x[1]), reverse=True)

# print(X)
q = []
ans = 0
for i in range(1, M + 1):
    while X and X[-1][0] <= i:
        _, b = X.pop()
        heappush(q, -b)
    if q:
        ans -= heappop(q)
        
print(ans)