Problem:


Score : 200 points

Problem Statement

You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.

A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.

Also, the given images are binary images, and the color of each pixel is either white or black.  

In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.

The image A is given as N strings A_1,...,A_N.

The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).

Similarly, the template image B is given as M strings B_1,...,B_M.

The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).  

Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.  

Constraints

1≦M≦N≦50 

A_i is a string of length N consisting of # and ..

B_i is a string of length M consisting of # and ..

Input

The input is given from Standard Input in the following format:

N M
A_1
A_2
:  
A_N
B_1
B_2
:  
B_M

Output

Print Yes if the template image B is contained in the image A. Print No otherwise.

Sample Input 1

3 2
#.#
.#.
#.#
#.
.#

Sample Output 1

Yes

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

Sample Input 2

4 1
....
....
....
....
#

Sample Output 2

No

The template image B, composed of a black pixel, is not contained in the image A composed of white pixels.



Sample input:
3 2
#.#
.#.
#.#
#.
.#


Sample output:
Yes

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
arr1=[[i for i in input()] for _ in range(n)]
arr2=[[i for i in input()] for _ in range(m)]
count=0
for i in range(n-m+1):
  for j in range(n-m+1):
    flag=True
    for k in range(m):
      for l in range(m):
        if arr1[i+k][j+l]!=arr2[k][l]:
          flag=False
    if flag:
      count+=1
if count>=1:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=[input() for _ in range(n)]
B=[input() for _ in range(m)]

ans='No'
flag=False
for i in range(n-m+1):
    for j in range(n-m+1):
        C=[A[i+k][j:j+m] for k in range(m)]
        if B==C:
            ans='Yes'
        
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,M = (int(_) for _ in input().split())
    A =[]
    B =[]
    for i in range(N):
        A.append(list(_ for _ in input()))
    for i in range(M):
        B.append(list(_ for _ in input()))

    for i in range(N-M+1):
        for j in range(N-M+1):
            # check
            flag = True
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        flag = False
                        break
            if(flag):
                ans = 'Yes'
                print(ans)
                exit()
            else:
                ans = 'No'


    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a_list=[input() for _ in range(n)]
b_list=[input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        f=True
        for k in range(m):
            for l in range(m):
                if a_list[i+k][j+l]!=b_list[k][l]:
                    f=False
                    break
            if not f:
                break
        if f:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())

hoge=[]
huga=[]
for i in range(n):
  hoge.append(list(input()))
  
for i in range(m):
  huga.append(list(input()))
ans=0
for i in range(1+n-m):
  for j in range(1+n-m):
    flag=0
    for k in range(m):
      for l in range(m):
        if(hoge[i+k][j+l]!=huga[k][l]):
          flag+=1
    if(flag==0):
      ans+=1
if(ans==0):
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
flag=0
for i in range(N-M+1):
	for j in range(N-M+1):
		for k in range(M):
			if A[i+k][j:j+M]!=B[k]:
				break
		else:
			flag=1
print('Yes' if flag else 'No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for _ in '1'*n]
b=[input() for _ in '1'*m]
for i in range(n-m+1):
	for j in range(n-m+1):
		c=[a[i+k][j:j+m]for k in range(m)]
		if b==c:print('Yes');exit()
print('No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for _ in '1'*n]
b=[input() for _ in '1'*m];
for i in range(n-m+1):
	for j in range(n-m+1):
		c=[a[i+k][j:j+m]for k in range(m)]
		if b==c:print('Yes');exit()
print('No')

Submission status: Accepted

Solution code:
import sys
N, M = map(int, input().split())
A = [input() for s in range(N)]
B = [input() for s in range(M)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        flg = 1
        for x in range(M):
            for y in range(M):
                if B[x][y] !=  A[i+x][j+y]:
                    flg = 0
        if flg == 1:
            print('Yes')
            sys.exit()
print('No')

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
s = []
for i in range(n):
    s.append(input())
t = []
for i in range(m):
    t.append(input())
found = False
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        f = True
        for k in range(m):
            for l in range(m):
                if t[k][l] != s[i+k][j+l]:
                    f = False
                    break
        if f == True:
            found = True

if found :
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:

import sys
n,m = map(int, input().split())
a = []
b = []
for i in range(n):
  a.append(list(input()))
  
for i in range(m):
  b.append(list(input()))


#

  
  
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = True
    for x in range(m):
      for y in range(m):
        if b[x][y] !=  a[i+x][j+y]:
          flag = False
          break
      if not flag:
        break
    else:
      print("Yes")
      sys.exit()
     
    

print("No")

Submission status: Accepted

Solution code:
import numpy as np

N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(list(input()))
B = []
for i in range(M):
    B.append(list(input()))
A = np.array(A)
B = np.array(B)


flag = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if np.all(A[i:i+M, j:j+M]==B):
            flag = True

if flag:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a_list = [input() for _ in range(n)]
b_list = [input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        f = True
        for k in range(m):
            for l in range(m):
                if a_list[i+k][j+l] != b_list[k][l]:
                    f = False
                    break
            if not f:
                break
        if f:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a_list = [input() for _ in range(n)]
b_list = [input() for _ in range(m)]
count = 0
res = []
for i in range(n-m+1):
    for j in range(n-m+1):
        f = True
        for k in range(m):
            for l in range(m):
                if a_list[i+k][j+l] != b_list[k][l]:
                    f = False
                    break
            if not f:
                break
        if f:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
# print(A)

B = [input() for _ in range(M)]
# print(B)

ans = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        check = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    check = False
        if check == True:
            ans = 'Yes'
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,m = map(int,input().split())
a = [0] * n
b = [0] * m
for i in range(n):
    a[i] = list(input())
for i in range(m):
    b[i] = list(input())

ans = False

for i in range(n-m):
    for j in range(n-m):
        match = 0
        for k in range(m):
            for l in range(m):
                if a[k+i][l+j] == b[k][l]:
                    match += 1
        if match == m * m:
            ans = True

if n == m:
    match = 0
    for k in range(m):
        for l in range(m):
            if a[k][l] == b[k][l]:
                match += 1
    if match == m * m:
        ans = True

if ans:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def do_match(A: list, B: list, offsets: tuple, size_B: int) -> bool:
    oh, ow = offsets
    for h in range(size_B):
        for w in range(size_B):
            if A[oh + h][ow + w] != B[h][w]:
                return False
    return True


def template_matching(N: int, M: int, A: list, B: list) -> bool:
    for offset_h in range(N - M + 1):
        for offset_w in range(N - M + 1):
            if do_match(A, B, (offset_h, offset_w), M):
                return True
    return False


if __name__ == "__main__":
    N = 0
    M = 0
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    yes = template_matching(N, M, A, B)
    print('Yes' if yes else 'No')

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
def f(n):
    if n == 1:
        return 14
    return n
a,b = LI()
if f(a) < f(b):
    print("Bob")
elif f(a) == f(b):
    print("Draw")
else:
    print("Alice")
"""

#B
n,m = LI()
a = SR(n)
b = SR(m)
for y in range(n-m+1):
    for x in range(n-m+1):
        h = y+m
        w = x+m
        f = 1
        for i in range(y,h):
            for j in range(x,w):
                if a[i][j] != b[i-y][j-x]:
                    f = 0
                    break
            if not f:
                break
        if f:
            print("Yes")
            quit()
print("No")
#C
"""
n,m = LI()
v = LIR(m)
p2 = [1]
for i in range(n):
    p2.append(p2[-1]*2)
dp = [[0 for i in range(p2[n])] for j in range(n)]
dp[0][1] = 1
for i in range(1,p2[n]):
    for k in range(n):
        for a,b in v:
            a -= 1
            b -= 1
            if k==a or k == b:
                c = p2[a]
                d = p2[b]
                if i&c and not i&d:
                    dp[b][i|d] += dp[k][i]
                if (not i&c) and i&d:
                    dp[a][i|c] += dp[k][i]
ans = 0
for i in range(1,n):
    ans += dp[i][-1]
print(ans)
"""

#D
"""
n,p,q = LI()
v = [None for j in range(n)]
sa = 0
sb = 0
for i in range(n):
    a,b,c = LI()
    v[i] = [a,b,c]
    sa += a
    sb += b
dp = [[[float("inf") for i in range(sb+1)] for j in range(sa+1)] for k in range(n+1)]
dp[0][0][0] = 0
for i in range(n):
    for a in range(sa):
        for b in range(sb):
            ai,bi,ci = v[i]
            if a + ai <= sa and b + bi <= sb:
                dp[i+1][a+ai][b+bi] = min(dp[i+1][a+ai][b+bi],dp[i][a][b]+ci,dp[i][a+ai][b+bi])
            dp[i+1][a][b] = min(dp[i+1][a][b],dp[i][a][b])
li = [[p,q]]
while li[-1][0] <= sa and li[-1][1] <= sb:
    li.append([li[-1][0]+p,li[-1][1]+q])
li.pop(-1)
ans = float("inf")
for a,b in li:
    ans = min(ans,dp[n][a][b])
if ans == float("inf"):
    print(-1)
else:
    print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [input() for _ in range(N)]
b = [input() for _ in range(M)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            for l in range(M):
                if a[i + k][j + l] != b[k][l]:
                    break
            else:
                continue
            break
        else:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A,B = [],[]

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

ans = ""
for i in range(N-M+1):
#  print(A[i])
  if B[0] in A[i]:
    ans += "T"
    y = A[i].find(B[0])
#    print("{}行目の{}文字目".format(i+1, y+1))
    for j in range(1,M):
      
      if A[i+j][y:y+M] == B[j]:
        ans += "T"
      else:
        ans += "F"
#      print(i, j, ans)

if "T" * M in ans:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
pic=[list(input()) for _ in range(N)]
temp=[list(input()) for __ in range(M)]
flag=0
for i in range(N-M+1):
    if flag==0:
        for j in range(N-M+1):
            if all(pic[x+j][i:i+M]==temp[x] for x in range(M)):
                print("Yes")
                flag=1
                break
if flag==0:print("No")

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))

A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        result = True
        for x in range(M):
            for y in range(M):
                sA = A[i + x][j + y]
                sB = B[x][y]
                if sA != sB:
                    result = False
                    break
            if result is False:
                break

        if result is True:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))

A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

result = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            s1 = A[i + k][j : j + M]
            s2 = B[k]
            if s1 != s2:
                break
        else:
            result = True
            break

if result == True:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=[]
B=[]
for i in range(n):
  a=list(input())
  A.append(a)
for i in range(m):
  b=list(input())
  B.append(b)
for i in range(n-m+1):
  for j in range(n-m+1):
    C=[]
    for k in range(m):
      c=A[k+j][i:i+m]
      C.append(c)
    if B==C:
      print('Yes')
      exit()
print('No')

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        flg = True
        for y in range(m):
            for x in range(m):
                if a[i+y][j+x] != b[y][x]:
                    flg = False
                    break
            if flg == False:
                break

        if flg:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            for l in range(M):
                if B[k][l] != A[k+i][l+j]:
                    break
            else:
                continue
            break
        else:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split());a=[input()for i in range(n)];b=[input()for i in range(m)];ans="No"
for i in range(n-m+1):
  for j in range(n-m+1):
    c=[a[i+k][j:j+m]for k in range(m)]
    if b==c:ans="Yes"
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
for i in range(N):
    A.append(list(input()))
B = []
for i in range(M):
    B.append(list(input()))
match = 0
for h in range(N-M+1):
    for w in range(N-M+1):
        if A[h][w]==B[0][0]:
            count = 0
            for bh in range(M):
                for bw in range(M):
                    if B[bh][bw]==A[h+bh][w+bw]:
                        count+=1
                    else:
                        count=-1
                        break
                if count==-1:
                    break
            if count==M*M:
                match=1
    if match==1:
        break

if match==0:
    print('No')
else:
    print('Yes')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        x=[]
        for k in range(m):
            x.append(a[i+k][j:j+m])
        if x==b:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        tmp = []
        for k in range(M):
            tmp.append(A[i+k][j:j+M])
        if tmp == B:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    for i in range(N-M+1):
        for j in range(N-M+1):
            ok = True
            for x in range(M):
                for y in range(M):
                    if A[i+x][j+y] != B[x][y]:
                        ok = False
            if ok:
                print("Yes")
                return
    print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A = [input() for i in range(N)]
B = [input() for i in range(M)]

ans = "No"

for i in range(N-M+1):
    for j in range(N-M+1):
        t = [k[j:j+M] for k in A[i:i+M]]
        if t == B:
            ans = "Yes"
 
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int,input().split())
a = np.array([list(input()) for i in range(n)])
b = np.array([list(input()) for i in range(m)])
ans = 'No'
for i in range(n-m+1):
    for j in range(n-m+1):
        if (a[j:j+m,i:i+m] == b).all():
            ans = 'Yes'
            break
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split(' '))
A=[input() for x in range(N)]
B=[input() for x in range(M)]
ans = 'No'
for h in range(0,(N-M)+1):
  for w in range(0,(N-M)+1):
    if sum([B[i]!=A[i+h][w:(w+M)] for i in range(M)])==0:
      ans = 'Yes'
      break
  if ans == 'Yes':
    break
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
def ic(x,y):
    for j in range(0,M):
        if B[j] != A[j+y][x:x+M]:return False
    else:return True
def sc():
    for j in range(0,N-M+1):
        for i in range(0,N-M+1):
            if ic(i,j):return True
    else:return False
print('Yes' if sc() else 'No')

Submission status: Accepted

Solution code:
'''
N, M = map(int, input().split())
A = list(list(input()) for _ in range(N))
B = list(list(input()) for _ in range(M))

ans = 'No'
d = N - M + 1
for i in range(d):
    for j in range(d):
        cnt = 0
        for x in range(M):
            if A[i+x][j:j+M+1] == B[x]:
                cnt += 1
            else:
                break
        if cnt == M:
            ans = 'Yes'
            break
    if ans == 'Yes':
        break

print(ans)
'''
N, M = map(int, input().split())
A = list(list(input()) for _ in range(N))
B = list(list(input()) for _ in range(M))

ans = 'No'
d = N - M + 1
for i_a in range(d):
    for j_a in range(d):
        cnt = 0
        for i_b in range(M):
            for j_b in range(M):
                if A[i_a + i_b][j_a + j_b] == B[i_b][j_b]:
                    cnt += 1
                else:
                    break
            
        if cnt == M**2:
            ans = 'Yes'
            break
    if ans == 'Yes':
        break

print(ans)

Submission status: Accepted

Solution code:
'''
N, M = map(int, input().split())
A = list(list(input()) for _ in range(N))
B = list(list(input()) for _ in range(M))

ans = 'No'
d = N - M + 1
for i in range(d):
    for j in range(d):
        cnt = 0
        for x in range(M):
            if A[i+x][j:j+M+1] == B[x]:
                cnt += 1
            else:
                break
        if cnt == M:
            ans = 'Yes'

print(ans)
'''
N, M = map(int, input().split())
A = list(list(input()) for _ in range(N))
B = list(list(input()) for _ in range(M))

ans = 'No'
d = N - M + 1
for i_a in range(d):
    for j_a in range(d):
        cnt = 0
        for i_b in range(M):
            for j_b in range(M):
                if A[i_a + i_b][j_a + j_b] == B[i_b][j_b]:
                    cnt += 1
                else:
                    break
            
        if cnt == M**2:
            ans = 'Yes'
            break
    if ans == 'Yse':
        break

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = False

for i in range(0, N-M+1):
    for j in range(0, N-M+1):
        sample = []
        for k in range(M):
            sample.append(A[i+k][j:j+M])
        if sample == B:
            flag = True
            break
   
print("Yes" if flag else "No")

Submission status: Accepted

Solution code:
N, M = [ int(x) for x in input().split() ]
As = [ input() for _ in range(N) ]
Bs = [ input() for _ in range(M) ]

def contain(i, j):
    for p in range(M):
        if As[i + p][j:j+M] != Bs[p]:
            return False
    return True
ans = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if contain(i, j):
            ans = True

print("Yes" if ans else "No")

Submission status: Accepted

Solution code:
n,m=(int(i) for i in input().split())
#print(n,m)
a=[]
for i in range(n):
    a.append(input())
#print(a)
b=[]
for i in range(m):
    b.append(input())
#print(b)
flag=0

for k in range(n-m+1):
  for j in range(n-m+1):
    cnt=0
    for i in range(m):
      if a[0+i+k][0+j:m+j]==b[0+i]:
        cnt+=1
    if cnt==m:
      flag=1
  
print('Yes' if flag==1 else 'No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

for x in range(n-m+1):
    for y in range(n-m+1):
        check = 0
        for i in range(m):
            for j in range(m):
                if a[x+i][y+j] != b[i][j]:
                    check = 1
                    break
            else:
                continue
            break
        if check == 0:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        s = [a[j:j+m] for a in A[i:i+m]]
        if s == B:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
flag=False
for y in range(1+N-M):
    if flag==True:break
    for x in range(1+N-M):
        if flag==True:break
        check=True
        for i in range(M):
            if check==False:break
            for j in range(M):
                if check==False:break
                if A[y+j][x+i]!=B[j][i]:
                    check=False
                    break
        if check==True:
            flag=True
            break
if flag==True:print('Yes')
else:print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
    row = list(map(str,input().split()))
    A.append(list(row[0]))
B = []
for i in range(M):
    row = list(map(str,input().split()))
    B.append(list(row[0]))

for i in range(N-M+1):
    for j in range(N-M+1):
        sub_A = [a[j:j+M] for a in A[i:M+i]]
        if sub_A == B:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = False
for i in range(0, N - M + 1):
  for j in range(0, N - M + 1):
    if B == [x[j:j+M] for x in A[i:i+M]]:
      flag = True
    if flag:
      break
  if flag:
    break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
picture = [input() for i in range(N)]
template = [input() for i in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        subpicture = [picture[row][j:j + M] for row in range(i, i + M)]
        if subpicture == template:
            print('Yes')
            break
    else:
        continue
    break
else:
    print('No')

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
a=[input() for i in range(n)]
b=[input() for i in range(m)]
result=True
for i in range(m):
    if (b[i] in a[i])==False:
        result=False
        break
print("Yes" if result else "No")

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

start=-1
for i in range(N):
    if B[0] in A[i]:
        start=i
        break
if start==-1 or start+M>N:
    print('No')
    exit()
else:
    for i in range(M):
        if (B[i] in A[start+i])!=1:
            print('No')
            exit()

print('Yes')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
aa = [input() for _ in range(n)]
bb = [input() for _ in range(m)]

match = False
for y in range(n-m+1):
    for x in range(n-m+1):
        target = ([''.join(aa[i][x:x+m]) for i in range(y, y+m)])
        if match or target == bb:
            match = True

print('Yes' if match else 'No')

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
A_portion = []
B = []
judge = 0

if(N < M):
  print('No')
else:
 for i in range(N):
   a = input() + '?'*(M)
   A.append(list(a))
 for i in range(M):
   list_dummy = list('?'*(len(a)))
   A.append(list_dummy)
  
 for i in range(M):
   b = input()
   B.append(list(b))

 for i in range(N):
  for j in range(N):
   for k in range(M):
    A_portion.append(A[j+k][i:i+M])
   #print(j+k,i,i+M-1)
   #print(A_portion)
   if(A_portion == B):
     judge = 1
   A_portion = []
    
 if(judge == 1):
   print('Yes')
 else:
   print('No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a = []
for i in range(n):
    a.append(input())
b = []
for i in range(m):
    b.append(input())

ok=False
for i in range(n-m+1):
    for j in range(n-m+1):
        cf=[]
        for l in range(m):
            cf.append(a[i+l][j:j+m])
            #print(cf)
            if cf==b:
                ok=True
print("Yes"if ok else "No")

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]


for j in range(0,n-m+1):
  for k in range(0,n-m+1):
    flag =True
    for row in range(m):
      for clm in range(m):
        if a[row+j][clm+k]!=b[row][clm]:
          flag = False
    if flag:
      print("Yes")
      exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

exist = False
for i in range(N-M+1):
    for j in range(N-M+1):
        match = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    match = False
        if match:
            exist = True
if exist:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
aa = [input() for _ in range(n)]
bb = [input() for _ in range(m)]

match = False
for y in range(n-m+1):
    for x in range(n-m+1):
        target = ([''.join(aa[i][x:x+m]) for i in range(y,y+m)])
        if match or target == bb:
            match = True

print('Yes' if match else 'No')

Submission status: Accepted

Solution code:
# coding: utf-8
n, m = map(int, input().split())
N = [input() for _ in range(n)]
M = [input() for _ in range(m)]
flg = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if all(M[k] == N[i + k][j : j + m] for k in range(m)):
            flg = True
            break
print(['No','Yes'][flg])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
for i in range(N):
  A.append(list(input()))
B = []
for j in range(M):
  B.append(list(input()))
for k in range(N-M+1):
  for l in range(N-M+1):
    cnt = 0
    if B[0][0:M] == A[k][l:l+M]:
      p = k
      q = l
      for m in range(M):
        if B[m][0:M] == A[p+m][q:q+M]:
          cnt += 1
        if cnt == M:
          print('Yes')
          exit()
print('No')

Submission status: Accepted

Solution code:
""" AtCoder """

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

for i in range(N - M + 1):
    for j in range(N - M + 1):
        count = 0
        for jj in range(M):
            if A[i + jj][j:j + M] != B[jj]:
                break
            count += 1
        if count == M:
            print("Yes")
            exit()

print("No")

Submission status: Accepted

Solution code:
n,m,*a=open(0).read().split();n,m=int(n),int(m);r=range(n-m+1);print('YNeos'[all(a[n:]!=[t[j:j+m]for t in a[i:i+m]]for i in r for j in r)::2])

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        total = 0
        for s in range(m):
            for k in range(m):
                if a[i+s][j+k] == b[s][k]:
                    total += 1
        if total == m*m:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

tmp = []
for a in A:
  for b in B:
    if(tmp != B):
      if(b in a):
        tmp.append(b)
    else:
      break
if(tmp == B):
  print('Yes')
else:
  print('No')