Harryxun/stf_run huggingface dataset:
n,k = map(int,input().split())
an = list(map(int, input().split()))
copyan = an[:]
i = copyan[0]
copyan[0]=10**6
movecount = 1
roopstart = 0
if i != 1:
    while True:
        memo = i
        i = copyan[i-1]
        
        
        if i >=30000:
            yokei = i%(10**6)
            
            break
        copyan[memo-1]=10**6 + movecount
        movecount += 1
        roopstart = i-1
else:
    print(1)
    exit()
roopnum = movecount - yokei
x = (k-yokei)%roopnum #移動する回数

ans = copyan.index(10**6+yokei+x) +1
print(ans)






### FIXED CODE ###

n,k = map(int,input().split())
an = list(map(int, input().split()))
copyan = an[:]
i = copyan[0]
copyan[0]=10**6
movecount = 1

if i != 1:
    while True:
        memo = i
        if k == movecount:
            print(i)
            
            exit()
        i = copyan[i-1]
        
        if i >=300000:
            yokei = i%(10**6)         
            break
        copyan[memo-1]=10**6 + movecount
        movecount += 1
        
else:
    print(1)
    exit()
roopnum = movecount - yokei
x = (k-yokei)%roopnum

ans = copyan.index(10**6+yokei+x) +1
print(ans)
input_line = int(input())

if input_line >= 1200
	print("ARC")
else
	print("ABC")

### FIXED CODE ###

input_line = int(input())

if input_line >= 1200:
	print("ARC")
else:
	print("ABC")
N = int(input())
output_list = []

for i in range(N):
  if i % 3 == 0 or i % 5 == 0 or i % 15 == 0:
  else:
    output_list.append(i)
  
print(sum(output_list)

### FIXED CODE ###

N = int(input())
output_list = [0]

for i in range(1,N+1):
  if i % 3 == 0 or i % 5 == 0 or i % 15 == 0:
    pass
  else:
    output_list.append(i)
  
print(sum(output_list))
N = [int(i) for i in input().split()]
     
if abs(N[2]-N[0]) <= N[3]:
  print(“Yes”)
elif abs(N[1]-N[0])+abs(N[2]-N[1]) <= 2*N[3]:
  print(“Yes”)
else:
  print(“No”)

### FIXED CODE ###

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

if abs(c-a) <= d:
	print('Yes')
elif abs(b-a) <= d and abs(c-b) <= d:
	print('Yes')
else:
	print('No')
n,m = map(int,input().split())
edge=[[] for _ in range(n)]
for _ in range(m):
    x,y = map(int,input().split())
    edge[x-1].append(y-1)


d = [0] * n

def dfs(v,edge):
    global depth
    depth = 0
    for next_v in edge[v]:
        if d[next_v] == 0:
            dfs(next_v,edge)
        else:
            depth = max(depth,d[next_v])
    depth += 1 
    d[v] = depth

for i in range(n):
    dfs(i,edge)
print(max(d)-1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

n,m = map(int,input().split())
edge=[[] for _ in range(n)]
for _ in range(m):
    x,y = map(int,input().split())
    edge[x-1].append(y-1)


d = [0] * n

def dfs(v,edge):
    depth = 0
    for next_v in edge[v]:
        if d[next_v] == 0:
            depth = max(depth,dfs(next_v,edge))
        depth = max(depth,d[next_v])
    depth += 1 
    d[v] = depth
    return depth

for i in range(n):
    dfs(i,edge)
print(max(d)-1)
X = int(input())
item = [100, 101, 102, 103, 104, 105]
dp = [[False for _ in range(X//100+3)] for _ in range(X+1)]
dp[0][0] = True
for x in range(X+1):
    for n in range(X//100+3):
        for i in item:
            if dp[x-i][n-1]:
                dp[x][n] = True
if True in dp[x]:
    print(1)
else:
    print(0)

### FIXED CODE ###

X = int(input())
dp = [False for _ in range(X+1)]
dp[0] = True
for x in range(X+1):
    if x > 99:
        item = [100, 101, 102, 103, 104, 105]
        for i in item:
            if dp[x-i]:
                dp[x] = True
if dp[X]:
    print(1)
else:
    print(0)
N = int(input())
s = [int(input()) for i in range(N)]
a = 10000000000
b = 1
for i in range(N - 1):
    a = min(a,s[i])
    if a >= s[i + 1]:
        b = b + 1
print(b)

### FIXED CODE ###

s = [(input().split()) for i in range(2)]
N = int(s[0][0])
t = s[1]
a = 1000000
b = 1
for i in range(N - 1):
    a = min(a,int(t[i]))
    c = int(t[i + 1])
    if a >= c:
        b = b + 1
print(b)
import sys
from collections import deque

def bfs(maze, visited):
    try:
        sy,sx=0,0
        gy,gx=H-1,W-1
        queue = deque([[sy, sx]])
        visited[sy][sx] = 0
        while queue:
            y, x = queue.popleft()
            if [y, x] == [gy, gx]:
                return visited[y][x]

            p=[]
            if x>0 : p.append([0,-1])
            if x<W-1: p.append([0,1])
            if y>0: p.append([-1,0])
            if y<H-1: p.append([1,0])
            for j, k in p:
                new_y, new_x = y+j, x+k
                if maze[new_y][new_x] == "." and \
                    visited[new_y][new_x] == -1:
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append([new_y, new_x])

    except RuntimeError:
        print(-1)


H,W=map(int,input().split())
m=[input() for i in range(H)]

ans=0
for i in range(H):
    for j in range(W):
        if m[i][j]==".": ans+=1

visited=[[-1]*W for i in range(H)]
try:
    print(ans-bfs(m,visited)-1)
except RuntimeError:
    print(-1)

### FIXED CODE ###

import sys
from collections import deque

def bfs(maze, visited):
    try:
        sy,sx=0,0
        gy,gx=H-1,W-1
        queue = deque([[sy, sx]])
        visited[sy][sx] = 0
        while queue:
            y, x = queue.popleft()
            if [y, x] == [gy, gx]:
                return visited[y][x]

            p=[]
            if x>0 : p.append([0,-1])
            if x<W-1: p.append([0,1])
            if y>0: p.append([-1,0])
            if y<H-1: p.append([1,0])
            for j, k in p:
                new_y, new_x = y+j, x+k
                if maze[new_y][new_x] == "." and \
                    visited[new_y][new_x] == -1:
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append([new_y, new_x])
        return -1

    except RuntimeError:
        print(-1)
        sys.exit()


H,W=map(int,input().split())
m=[input() for i in range(H)]

ans=0
for i in range(H):
    for j in range(W):
        if m[i][j]==".": ans+=1

visited=[[-1]*W for i in range(H)]
p=bfs(m,visited)
print( p if p==-1 else ans-p-1)
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
	if i % 2 == 0 and A[i] % 2 == 1:
    	count += 1
print(count)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
  if i % 2 == 0 and A[i] % 2 == 1:
    count += 1
print(count)
from collections import deque
H,W=map(int,input().split())
L=[]
l=["#"]*(W+2)
L.append(l)
cnt=0
for i in range(H):
    s=input()
    s="#"+s+"#"
    l=[]
    for j in range(W+2):
        l.append(s[j])
        if s[j]==".":
            cnt+=1
    L.append(l)
l=["#"]*(W+2)
L.append(l)
#print(L)
D=deque([[1,1,1]])
for x in range(1000000):
    if H==D[0][0] and W==D[0][1]:
        print(cnt-D[0][2])
        exit()
    else:
        if L[D[0][0]+1][D[0][1]]==".":
            D.append([D[0][0]+1,D[0][1],D[0][2]+1])
        if L[D[0][0]][D[0][1]+1]==".":
            D.append([D[0][0],D[0][1]+1,D[0][2]+1])
        if L[D[0][0]-1][D[0][1]]==".":
            D.append([D[0][0]-1,D[0][1],D[0][2]+1])
        if L[D[0][0]][D[0][1]-1]==".":
            D.append([D[0][0],D[0][1]-1,D[0][2]+1])
        L[D[0][0]][D[0][1]]="#"
        D.popleft()
            

### FIXED CODE ###

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

A=[]
a=["#"]*(W+2)
A.append(a)
for i in range(H):
    s=input()
    s="#"+s+"#"
    A.append(list(s))
A.append(a)
#幅優先探索
#print(A)
P=[[1,1]]
A[1][1]=1
x=[1,-1,0,0]
y=[0,0,1,-1]
while P!=[]:
    #print(P)
    for j in range(4):
        if A[P[0][0]+x[j]][P[0][1]+y[j]]=="#":
            pass
        elif A[P[0][0]+x[j]][P[0][1]+y[j]]==".":
            A[P[0][0]+x[j]][P[0][1]+y[j]]=A[P[0][0]][P[0][1]]+1
            P.append([P[0][0]+x[j],P[0][1]+y[j]])
        elif A[P[0][0]+x[j]][P[0][1]+y[j]]<=A[P[0][0]][P[0][1]]+1:
            pass
        else:
            A[P[0][0]+x[j]][P[0][1]+y[j]]=A[P[0][0]][P[0][1]]+1
            P.append([P[0][0]+x[j],P[0][1]+y[j]])
    del P[0]
S=0
for i in range(H+2):
    for j in range(W+2):
        if A[i][j]=="#":
            S+=1
if A[H][W]==".":
    print(-1)
else:
    print((H+2)*(W+2)-S-A[H][W])
from fractions import gcd

INF = 2 << 30
V = 1002
G = [[] for _ in xrange(V)]
visited = [False]*V

def add_edge(fro, to, cap):
    G[fro].append([to,cap,len(G[to])])
    G[to].append([fro,0,len(G[fro])-1])

def dfs(v,t,f):
    if v == t:
        return f
    visited[v] = True
    for i,(to,cap,rev) in enumerate((G[v])):
        if visited[to] or cap == 0:
            continue        
        d = dfs(to,t,min(f,cap))
        if d > 0:
            G[v][i][1] -= d
            G[to][rev][1] += d
            return d
    return 0

def max_flow(s,t):
    flow = 0
    dbg = 0
    while True:
        for i in xrange(V):
            visited[i] = False
        f = dfs(s,t,INF)
        if f == 0:
            return flow
        flow += f
        dbg += 1
        if dbg > 600:
            return -1

while True:
    m,n = map(int,raw_input().split())
    if m|n == 0:
        break
    V = m+n+2
    G = [[] for _ in xrange(V)]
    visited = [True] * V
    data = []
    while len(data) < n+m:
        data += map(int,raw_input().split())
    blue = data[:m]
    red = data[m:]
    for i in xrange(m):
        add_edge(V-2,i,1)
    for i in xrange(m,m+n):
        add_edge(i,V-1,1)
    for i,b in enumerate(blue):
        for j,r in enumerate(red,m):
            if gcd(b,r) != 1:
                add_edge(i,j,1)
    print max_flow(V-2,V-1)

### FIXED CODE ###

from fractions import gcd

V = 1001
G = []
visited = []
match = []

def add_edge(u,v):
    G[u].append(v)
    G[v].append(u)

def dfs(v):
    visited[v] = True
    for u in G[v]:
        w = match[u]
        if w < 0 or not visited[w] and dfs(w):
            match[v] = u
            match[u] = v
            return True

def bipartite_matching():
    global match,visited
    res = 0
    match = [-1]*V
    for v in xrange(V):
        if match[v] < 0:
            visited = [False]*V
            if dfs(v):
                res += 1
    return res

while True:
    m,n = map(int,raw_input().split())
    V = m+n
    if V == 0:
        break
    G = [[] for _ in xrange(V)]
    data = []
    while len(data) < V:
        data += map(int,raw_input().split())
    for i,b in enumerate(data[:m]):
        for j,r in enumerate(data[m:],m):
            if gcd(b,r) != 1:
                add_edge(i,j)
    print bipartite_matching()
import math
N, K = input().split()
print(math.floor(math.log(N) / math.log(K)) + 1)

### FIXED CODE ###

def base_changer(number,base):
    buff=97+abs(base-10)
    dic={};buff2='';buff3=10
    for i in range(97,buff+1):
        dic[buff3]=chr(i)
        buff3+=1   
    while(number>=base):
        mod=int(number%base)
        number=int(number//base)
        if (mod) in dic.keys():
            buff2+=dic[mod]
            continue
        buff2+=str(mod)
    if (number) in dic.keys():
        buff2+=dic[number]
    else:
        buff2+=str(number)

    return buff2[::-1]  
N,K = map(int, input().split())
print(len(base_changer(N,K)))
x,t=map(int,input().split)
print(max(0,x-t)

### FIXED CODE ###

x,t=map(int,input().split())
print(max(0,x-t))
a, b, h = map(int, input().split())
print ((a+b)*h //2)

### FIXED CODE ###

a = int(input())
b = int(input())
h = int(input())
print ((a+b)*h //2)
a, b =map(in, input().split())
print((a+b)%24)

### FIXED CODE ###

a, b = map(int, input().split())
print((a + b)%24)
n,m=map(int,input().split())
ac=0
ans=[True]*n
wa=[0]*n
for i in range(m):
    p,s=input().split()
    p=int(p)-1
    if s=="AC" and ans[p]:
        ans[p]=False
        ac+=1
    elif s=="WA" and ans[p]:
        wa[p]+=1

cnt=0
for i in range(n):
    if not ans[i]:
        cnt+=wa[i]

print(ac,cnt)

### FIXED CODE ###

from collections import defaultdict
import heapq
import math

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

edges = defaultdict(list)
field = []

for _ in range(H):
    field.append(input())

weight = 1
for i in range(H):
    for j in range(W):
        if j + 1 < W and field[i][j] == '.' and field[i][j + 1] == '.':
            edges[W * i + j].append((W * i + j + 1, weight))
            edges[W * i + j + 1].append((W * i + j, weight))
        if i + 1 < H and field[i][j] == '.' and field[i + 1][j] == '.':
            edges[W * i + j].append((W * (i + 1) + j, weight))
            edges[W * (i + 1) + j].append((W * i + j, weight))


def dijkstra(s):
    que = []
    dist = [float('inf')] * (H * W)
    dist[s] = 0
    heapq.heappush(que, (0, s))

    while que:
        p = heapq.heappop(que)
        v = p[1]
        if dist[v] < p[0]:
            continue
        for i in range(len(edges[v])):
            e = edges[v][i]
            if dist[e[0]] > dist[v] + e[1]:
                dist[e[0]] = dist[v] + e[1]
                heapq.heappush(que, (dist[e[0]], e[0]))

    dist = [0 if d == float('inf') else d for d in dist]
    return dist


ans = 0
for i in range(H*W):
    ans = max(ans, max(dijkstra(i)))

print(ans)
r = int(raw_input())

s = math.pi*r*r
l = 2.0*math.pi*r

print s, l

### FIXED CODE ###

import math

r = float(input())

s = math.pi * r**2
l = 2.0*math.pi*r

print(s, l)
import sys
sys.setrecursionlimit(10**8)

N = int(input())
A = list(map(int,(input().split())))
Q = int(input())
num_list = [0]*(N+1)
s = []
for i in range(N):
    num_list[A[i]] += 1
for _ in range(Q):
    s_s = 0
    B,C = map(int,(input().split()))
    num_list[C] += num_list[B]
    num_list[B] = 0
    for j in range(N+1):
        s_s += (j)*num_list[j]
    s.append(s_s)
for i in range(Q):
    print(s[i])


### FIXED CODE ###

import sys,collections
input = sys.stdin.readline

N=input().rstrip()
A=list(map(int,input().split()))
Ac = collections.Counter(A)
Q = int(input())
for i in range(Q):
    B,C = list(map(int,input().split()))
    nb = Ac[B]
    Ac[C] += Ac[B]
    Ac[B] = 0

    if i==0:
        ans = 0
        for key,val in Ac.items():
            ans += key*val
    else:
        ans +=nb*C - nb*B
    
    print(ans)
n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
d=0
for i in [n//2-1,n//2]:
    c=1
    A=a[i]
    for j in range(i+1)[A:i+1]:
        c*=j
    for k in range(1,A+1):
        c/=k
    if d < c:
        d=c
print(b,d)


### FIXED CODE ###

n=int(input())
a=sorted(list(map(int,input().split())))
b=a.pop(-1)
print(b,min(a,key=lambda x :abs(b-2*x)))
while True:
    m=input().split()
    h=int(m[0])
    w=int(m[1])
    if a==0&b==0:
      break
    for i in range(h):
       print("#"*w)
    
    


### FIXED CODE ###

while True:
    v=input().split()
    a=int(v[0])
    b=int(v[1])
    if a==0 and b==0:
       break
    for i in range (a):
        print('#'*b)
    print()
import bisect


A, B, Q = map(int, input().split())
s = [-10 ** 9] + [int(input()) for _ in range(A)] + [10 ** 9]
t = [-10 ** 9] + [int(input()) for _ in range(B)] + [10 ** 9]
x = [int(input()) for _ in range(Q)]
for i in x:
    si = bisect.bisect_left(s, i)
    ti = bisect.bisect_left(t, i)
    s1, s2 = s[si - 1], s[si]
    t1, t2 = t[ti - 1], t[ti]
    ans = 10 ** 9
    for ss in [s1, s2]:
        for tt in [t1, t2]:
            ans = min(ans, abs(i - ss) + abs(ss - tt),
                      abs(i - tt) + abs(ss - tt))
    print(ans)

### FIXED CODE ###

import bisect


A, B, Q = map(int, input().split())
s = [-10 ** 12] + [int(input()) for _ in range(A)] + [10 ** 12]
t = [-10 ** 12] + [int(input()) for _ in range(B)] + [10 ** 12]
x = [int(input()) for _ in range(Q)]
for i in x:
    si = bisect.bisect_left(s, i)
    ti = bisect.bisect_left(t, i)
    s1, s2 = s[si - 1], s[si]
    t1, t2 = t[ti - 1], t[ti]
    ans = 10 ** 12
    for ss in [s1, s2]:
        for tt in [t1, t2]:
            ans = min(ans, abs(i - ss) + abs(ss - tt),
                      abs(i - tt) + abs(ss - tt))
    print(ans)
S = input()
L = int(S)
D = L-2
A = int(D)
G = L-1
Z = int(G)
B = L-3
V = int(B)

if L==0:
    print(0)

elif L==1:
    print(0)

elif L==2:
    print(2)

elif L>=3:
    print((10*A*Z+8*U+10*B)%(10**9+7))



### FIXED CODE ###

N = input()
M = int(N)

A = 9**M
a = int(A)
B = 9**M
b = int(B)
C = 8**M
c = int(C)
D = a+b-c
d = int(D)
E = 10**M
e = int(E)
F = e-d
f = int(F)

if M==0:
    print(0)

elif M==1:
    print(0)

elif M==2:
    print(2)

elif M>=3:
    print(f%(10**9+7))
N = input()
D = [i for i in input()]
M = input()
T = [i for i in input()]

for d in D:
    if t in T:
        T.remove(t)
    if len(T)==0:
        print("YES")
        quit()
print("NO")

### FIXED CODE ###

from collections import Counter
N = input()
D = Counter([i for i in input().split()])
M = input()
T = Counter([i for i in input().split()])
for key, value in T.items():
    try:
        if D[key] < value:
            print("NO")
            break
    except:
        print("NO")
        break
else:
    print("YES")
strargs = [10, 3, ]

n, a, b = map(lambda x: int(x), strargs)

if (b - a) % 2 == 0:
  print(int((b - a)/2))
  
elif n - a < b - 1:
  print(n - a)

else:
  print(b - 1)

### FIXED CODE ###

strargs = input()

n, a, b = map(lambda x: int(x), strargs.split())

if (b - a) % 2 == 0:
  print((b - a)//2)
  
elif a - 1 < n - b:
  newB = b - a
  mid = (newB - 1)//2 + 1
  print(a + mid - 1)

else:
  newA = (a + (n - b + 1))
  mid = newA + (n - newA)//2
  print((n - b + 1) + (n - newA)//2)
S,T =.input().split()
print("T"+"S")

### FIXED CODE ###

S,T =input().split()
print(T+S)
n,m=map(int,input().split())
d={}
for i in range(5):
    d[i]=0
for i in range(m):
    a,b=map(int,input().split())
    d[a-1]+=1
    d[b-1]+=1
for i in range(n):
    print(d[i])

### FIXED CODE ###

n,m=map(int,input().split())
d={}
for i in range(n):
    d[i]=0
for i in range(m):
    a,b=map(int,input().split())
    d[a-1]+=1
    d[b-1]+=1
for i in range(n):
    print(d[i])
a, b = map(int,input().split())
if a <= 5:
  print(0)
elif a < = 12:
  print(b//2)
else:
  print(b)

### FIXED CODE ###

a, b = map(int,input().split())
if a <= 5:
  print(0)
elif a <= 12:
  print(b//2)
else:
  print(b)
N,T =map(int,input().split())
t = map(int,input().split())
amount =0


    
for index in range(N-1):
    t_sub = t[index+1]-t[index]
    amount+=min(t_sub,T)

        
amount +=T

print(amount)

### FIXED CODE ###

if __name__ == '__main__':
    N, T = map(int, input().split())
    ts = list(map(int, input().split()))
    
    
amount =0


    
for index in range(N-1):
    t_sub = ts[index+1]-ts[index]
    amount+=min(t_sub,T)

        
amount +=T

print(amount)
a, b, k = map(int, input().split())
nums = list(range(a, b+1))
for i in range(a, b+1):
  if nums.index(i) <= k - 1 or nums[::-1].index(i) <= k - 1:
    print(i)
  

### FIXED CODE ###

a, b, k = map(int, input().split())
n = range(a, b+1)
for i in sorted(set(n[:k]) | set(n[-k:])):
  print(i)
N, K = [int(x) for x in input().split(' ')]
A = [int(x) for x in input().split(' ')]
r = sorted([A[i] * A[j] for i in range(N) for j in range(i+1, N)])
print(r[K-1])

### FIXED CODE ###

N = int(input())
l = {}
for _ in range(N):
  s = input()
  l.setdefault(s, 0)
  l[s] += 1
l = sorted([(v, k) for k, v in l.items()])
c = l[-1][0]
r = []
for i in range(-1, -len(l)-1, -1):
  if l[i][0] < c:
    break
  r.append(l[i][1])
for x in reversed(r):
  print(x)
n, m = map(int, input().split())
r = [0] * n
for _ in range(m):
  a, b = map(int, input().split())
  r[a] += 1
  r[b] += 1
for i in range(n):
  print(r[i])


### FIXED CODE ###

n, m = map(int, input().split())
r = [0] * n
for _ in range(m):
  a, b = map(int, input().split())
  r[a - 1] += 1
  r[b - 1] += 1
for i in range(n):
  print(r[i])
# -*- coding:utf-8 -*-
import sys

def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if 0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym:
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]
sys.setrecursionlimit(10000000)
while True:
	counter+=1
	line = input()
	if ' ' in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(N)] for j in range(M)]
	else:
		tile[counter-2] = list(line)
	if N is 0 and M is 0:
		break
	if counter-1 is M:
		solve()
		counter = 0

### FIXED CODE ###

# -*- coding:utf-8 -*-
import sys
def dfs(x, y, sym):
	tile[x][y] = "."
	for i in range(len(DX)):
		nx = x + DX[i]
		ny = y + DY[i]
		if (0<=nx and nx<N and 0<=ny and ny<M and tile[nx][ny] is sym):
			dfs(nx, ny, sym)

def solve():
	res = 0
	for i in range(N):
		for j in range(M):
			sym = tile[i][j]
			if tile[i][j] != ".":
				if tile[i][j] is sym:
					dfs(i, j, sym)
					res += 1
	print(res)

counter=0
DX = [-1,0,1,0]
DY = [0,-1,0,1]
sys.setrecursionlimit(10**7)
while True:
	line = input()
	if " " in line:
		nums = line.split(" ")
		N = int(nums[0])
		M = int(nums[1])
		tile = [[0 for i in range(M)] for j in range(N)]
	else:
		tile[counter-1] = list(line)
	if N is 0 and M is 0:
		break
	counter += 1
	if counter-1 is N:
		solve()
		counter = 0
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    H, W = map(int, input().split())
    maze = [[_ for _ in input()] for _ in range(W)]
    INF = 10 ** 10
    # dp[i][j]:=(i,j)に到達するまでに黒壁を壊す回数の最小値
    dp = [[INF] * W for _ in range(H)]

    if maze[0][0] == '#':
        dp[0][0] = 1
    else:
        dp[0][0] = 0

    for i in range(H):
        for j in range(W):
            for [dy, dx] in [[1, 0], [0, 1]]:
                ny, nx = i + dy, j + dx
                if ny >= H or nx >= W:
                    continue
                else:
                    if maze[i][j] == '.' and maze[ny][nx] == '#':
                        dp[ny][nx] = min(dp[ny][nx], dp[i][j] + 1)
                    else:
                        dp[ny][nx] = min(dp[ny][nx], dp[i][j])
    print(dp[W-1][H-1])


resolve()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    H, W = map(int, input().split())
    maze = [[_ for _ in input()] for _ in range(W)]
    INF = 10 ** 5
    # dp[i][j]:=(i,j)に到達するまでに黒壁を壊す回数の最小値
    dp = [[INF] * W for _ in range(H)]

    if maze[0][0] == '#':
        dp[0][0] = 1
    else:
        dp[0][0] = 0

    for i in range(H):
        for j in range(W):
            for [dy, dx] in [[1, 0], [0, 1]]:
                ny, nx = i + dy, j + dx
                if ny >= H or nx >= W:
                    continue
                else:
                    if maze[i][j] == '.' and maze[ny][nx] == '#':
                        dp[ny][nx] = min(dp[ny][nx], dp[i][j] + 1)
                    else:
                        dp[ny][nx] = min(dp[ny][nx], dp[i][j])
    print(dp[H - 1][W - 1])


resolve()
# -*- coding: utf-8 -*-
"""
Created on Wed May  2 21:28:06 2018
ALDS1_5a
@author: maezawa
"""
import itertools as itr

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

for i in m:
    yesorno = False
    b = []
    for j in a:
        if j <= i:
            b.append(j)
    #print(b)
    lb = len(b)
    if lb >= 1:
        for r in range(1, 2**lb):
            fmt = '0'+str(lb)+'b'
            bin_str = format(r, fmt)
            sumb = sum([b[k]*int(bin_str[k]) for k in range(lb)])    #print(i,comb)
            if sumb == i:
                yesorno = True
                break
            if yesorno:
                break
    if yesorno:
        print('yes')
    else:
        print('no')


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed May  2 21:28:06 2018
ALDS1_5a_r1  
@author: maezawa
"""
import itertools as itr

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

sum_array = []
for r in range(1,n+1):
    for comb in itr.combinations(a, r):
        sum_array.append(sum(comb))
sum_array.sort()

for i in m:
    left = 0
    right = len(sum_array)
    yesorno = 'no'
    while(left < right):
        #print(left, right)
        mid = (left+right)//2
        if sum_array[mid] == i:
            yesorno = 'yes'
            break
        elif sum_array[mid] > i:
            right = mid
        else:
            left = mid+1
            
    print(yesorno)