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.

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

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 a[i+k][j+l]!=b[k][l]:
                    flag=False
        if flag:
            print("Yes")
            exit()
print("No")

Solution (Python):
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):
        flag=True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]!=b[k][l]:
                    flag=False
        if flag:
            print("Yes")
            exit()
print("No")

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

def check(i, j):
    cnt=0
    for k in range(M):
        for l in range(M):
            if A[i+k][j+l] == B[k][l]:
                cnt += 1
    if cnt==M**2:
        return True
    
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = check(i, j)
            if flg:
                break
    if flg:
        break
            
ans='Yes' if flg else 'No'
print(ans)

Solution (Python):
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
lenB = M**2
flg=False
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            cnt=0
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] == B[k][l]:
                        cnt += 1
            if cnt==M**2:
                flg=True
ans='Yes' if flg else 'No'
print(ans)

Solution (Python):
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N,M = LMIIS()
    A = [0]*N
    for i in range(N):
        A[i] = input()
    B = [0]*M
    for i in range(M):
        B[i] = input()
    if M > N:
        print('No')
        return
    for i in range(N-M+1):
        for j in range(N-M+1):
            found = True
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        found = False
                        break
                if not found:
                    break
            if found:
                print('Yes')
                return
    print('No')



if __name__ == '__main__':
    main()

Solution (Python):
import math  
import bisect  
import queue  


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [[a for a in input()] for _ in range(N)]
    B = [[b for b in input()] for _ in range(M)]

    ans = False
    for i in range(0, N - M + 1):
        for j in range(0, N - M + 1):
            res = True
            for k in range(0, M):
                for l in range(0, M):
                    if A[i + k][j + l] != B[k][l]:
                        res = False
            if res:
                ans = True
                break

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    
    def check(y, x):
        res = True
        for dy in range(M):
            for dx in range(M):
                if A[y + dy][x + dx] != B[dy][dx]:
                    res = False
                    break
            if not res:
                break
        return res
    
    for sy in range(N - M + 1):
        for sx in range(N - M + 1):
            if check(sy, sx):
                print('Yes')
                exit()
    print('No')


if __name__ == '__main__':
    solve()

Solution (Python):
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): 
            
            
            if a[i+k][j:m+j]!=b[k]:
                break
        else:
            print("Yes")
            exit()

print("No")

Solution (Python):
n, m = map(int, input().split())
list_A = [ list(input()) for _ in range(n) ]
list_B = [ list(input()) for _ in range(m) ]
ans = "No"
for i in range(n-m):
    for j in range(n-m):
        cnt = 0
        for k in range(i, i+m):
            for l in range(j, j+m):
                if list_B[k-i][l-j] == list_A[k][l]:
                    cnt += 1
        if cnt == m*m:
            ans = "Yes"

if n == 1 and m == 1:
    if list_A[0][0] == list_B[0][0]:
        ans = "Yes"

print(ans)

Solution (Python):
import sys

n,m = map(int,input().split())
a = [[] for i in range(n)]
b = [[] for j in range(m)]
for i in range(n):
    a[i] = input()
for i in range(m):
    b[i] = input()
    
mal = n-m+1
for i in range(mal):
    for j in range(mal):
        fl = 1
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    fl = 0
                    
        if fl == 1:
            print("Yes")
            sys.exit()
            
print("No")

Solution (Python):
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
for y in range(n-m+1):
    for z in range(n-m+1):
        count = 0
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count += 1
                if count == m:
                    print("Yes")
                    exit()
            else:
                count = 0
print("No")

Solution (Python):
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)
for i in range(n-m+1):
    for j in range(n-m+1):
        if (a[i:i+m, j:j+m] == b).all():
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Solution (Python):
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
count = 0
for y in range(n-m+1):
    for z in range(n-m+1):
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count +=1
            if count == m:
                print("Yes")
                exit()
        count=0
print("No")

Solution (Python):
import numpy as np

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

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

answer = 'Yes' if bl else 'No'
print(answer)

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

A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for x in range(N - M + 1):
    for y in range(N - M + 1):
        isContain = True
        for i in range(M):
            for j in range(M):
                a = A[i + x][j + y]
                b = B[i][j]
                isContain &= (a == b)
        if isContain:
            ans = 'Yes'
            break
    else:
        continue
    break
else:
    ans = 'No'

print(ans)

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

    for h in range(N - M + 1):
        for w in range(N - M + 1):
            flag = True
            for i in range(M):
                for j in range(M):
                    if A[h + i][w + j] == B[i][j]:
                        continue
                    else:
                        flag = False
                        break
                if not flag:
                    break
            if flag:
                print("Yes")
                return
    else:
        print("No")


main()

Solution (Python):
n, m = map(int, input().split())
nl = []
ml = []
for _ in range(n):
    nl.append(input())
for _ in range(m):
    ml.append(input())
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = True
        for k in range(0, m):
            for l in range(0, m):
                if nl[i+k][j+l] != ml[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
print(['No', 'Yes'][flag])

Solution (Python):
icase=0
if icase==0:
    n,m=map(int,input().split())
    a=[""]*n
    for i in range(n):
        a[i]=input()
    b=[""]*m
    for i in range(m):
        b[i]=input()



    for ni in range(n-m+1):
        for nj in range(n-m+1):
            yn=""
            for im in range(m):

                if a[ni+im][nj:nj+m]!=b[im]:
                    yn="NG"
                    break
            if yn=="NG":
                continue
            if yn=="":
                yn="OK"
                break
        if yn=="OK":
            break
        else:
            continue
    if yn=="OK":
        print("Yes")
    else:
        print("No")

Solution (Python):
n, m = map(int, input().split())
map_n = [0]*n
for i in range(n):
  map_n[i] = input()
map_m = [0]*m
for i in range(m):
  map_m[i] = input()

ans = False
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = False
    for p in range(m):
      for q in range(m):
        if map_n[i+p][j+q] != map_m[p][q]:
          flag = True
          break
      if flag:
        break
    if not flag:
      ans = True
      break
  if ans:
    break

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

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

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    n, m = MII()
    aa = [IS() for _ in range(n)]
    bb = [IS() for _ in range(m)]
    for i in range(n-m+1):
        for j in range(n-m+1):
            for k in range(m):
                if aa[i+k][j:j+m] != bb[k][:]: break
            else: print('Yes'); exit()
    print('No')

if __name__ == '__main__':
    main()

Solution (Python):
import sys
n, m = map(int, input().split())
    
array1 = [list(input()) for _ in range(n)]
array2 = [list(input()) for _ in range(m)]
    
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if array1[i+k][j:j+m] != array2[k][:]:
                break
        else:
            print("Yes")
            sys.exit()
print("No")

Solution (Python):
N, M = [int(x) for x in input().split()]

A = []
B = []
C = []

for i in range(N):
    A += [list(input())]

for i in range(M):
    B += [list(input())]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        ans = 'Yes'


        for bi in range(M):
            for bj in range(M):
                if A[i+bi][j+bj] != B[bi][bj]:
                    ans = 'No'
                    break
            if ans == 'No':
                break


        if ans == 'Yes':
            break
    if ans == 'Yes':
        break

print (ans)

Solution (Python):
N,M=map(int,input().split())
A=[0 for k in range(N)]
B=[0 for k in range(M)]
for i in range(N):
    A[i]=input()
for i in range(M):
    B[i]=input()
L=N-M
mark=0
import sys
for k in range(L+1):
    for l in range(L+1):
        count=0
        for i in range(M):    
            for j in range(M):
                if B[i][j]==A[i+k][j+l]:
                    count+=1
                else:
                    break
        if mark==0 and count==M**2:
            print("Yes")
            mark=1
            sys.exit()
if mark==0:
    print("No")

Solution (Python):





n, m = map(int, input().split())
a = []
b = []
is_contain = True

for i in range(n):
    a.append(input())

for i in range(m):
    b.append(input())

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

        
        if count == m*m:
            print("Yes")
            exit()


print("No")

Solution (Python):
import numpy as np
N, M = map(int, input().split())
A = np.array([list(input()) for _ in range(N)])
B = np.array([list(input()) for _ in range(M)])
for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M, j:j+M] == B).all():
      print('Yes')
      exit()
print('No')

Solution (Python):
import numpy as np
 
N,M = map(int,input().split())
A = np.array([list(input()) for _ in range(N)])
B = np.array([list(input()) for _ in range(M)])
 
bl = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M] == B).all():
      bl = True
 
answer = 'Yes' if bl else 'No'
print(answer)

Solution (Python):
N,M = map(int,input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]
d = N-M+1
for i in range(d):
    for j in range(d):
        flag = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]==B[k][l]:
                    continue
                else:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
def main():
    N, M = map(int, input().split())
    target = list()
    pattern = list()

    for n in range(N):
        l = input()
        target.append(l)

    for m in range(M):
        l = input()
        pattern.append(l)

    find = 0

    for i in range(N):
        for j in range(N):

            if ( i + (M - 1) <= N - 1 ) and (j + (M - 1) <= N - 1)  :
                count = 0

                for k in range(M):
                    for l in range(M):
                        if target[i+k][j+l] != pattern[k][l]:
                            count += 1
                if count == 0:
                    find += 1
                        
    if find:
        print("Yes")
    else:
        print("No")
main()

Solution (Python):
n, m = map(int, input().split())
a, b = [], []
for i in range(n):
    s = input()
    assert len(s) == n
    a.append(s)
for j in range(m):
    s = input()
    assert len(s) == m
    b.append(s)


def scan(i1, j1):
    for i2 in range(m):
        if a[i1+i2][j1:j1+m] != b[i2]:
            return False
    return True


def solve():
    for i1 in range(n-m+1):
        for j1 in range(n-m+1):
            if scan(i1, j1):
                return True
    return False


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

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

def check():
    for i in range(N-M+1):
        for j in range(N-M+1):
            if B[0] == A[i][j:j+M]:
                for k in range(1,M):
                    if B[k] != A[i+k][j:j+M]:
                        break
                else:
                    return True
    return False

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

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

def check():
    for i in range(N-M+1):
        for j in range(N-M+1):
            if B[0] == A[i][j:j+M]:
                for k in range(1,M):
                    if B[k] != A[i+k][j:j+M]:
                        break
                else:
                    return True
    return False

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

Solution (Python):
n,m = map(int,input().split())
a = []
b = []
ans = False
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
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:
            ans = True
if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
n, m = map(int, input().split())
a = list()
for _ in range(n):
    a.append(str(input()))
b = list()
for _ in range(m):
    b.append(str(input()))

for H in range(n if m == 1 else n-m+1):
    for W in range(n if m == 1 else n-m+1):
        cnt = 0
        for M in range(m):
            if a[H+M][0+W:m+W] == b[M]:
                cnt+=1
        if cnt==m:
            print('Yes')
            exit()

print('No')

Solution (Python):
def main():

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

    for i in range(n-m+1):
        for j in range(n-m+1):
            tmp_a = []
            for k in range(i,i+m):
                tmp_a.extend(a[k][j:j+m])
            
            
            
            if b == tmp_a:
                print('Yes')
                return
    print('No')

if __name__ == '__main__':
    main()

Solution (Python):
N,n=map(int,input().split())
L=[]
for i in range(N):
    a=list(input())
    L.append(a)

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



for H in range(N-n+1):
    for W in range(N-n+1):
        F=0
        if F!=1:
            for h in range(n):
                if F!=1:
                    for w in range(n):
                        if L[h+H][w+W]!=l[h][w]:
                            F=1
        if F==0:
            print("Yes")
            
            exit()
print("No")

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
a = []
b = []
for i in range(n):
    a.append(ins())
for i in range(m):
    b.append(ins())
for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            if a[i+k][j:j+m]!=b[k]:
                ok = False
                break
        if ok:
            print('Yes')
            exit()
print('No')

Solution (Python):




import sys
input = sys.stdin.readline



def main():
    N,M = map(int,input().split())
    A = [input().rstrip() for i in range(N)]
    B = [input().rstrip() for i in range(M)]

    res = 'No'

    for i in range(N-M+1):
        for j in range(N-M+1):
            for k in range(M):
                if A[j+k][i:i+M] != B[k]:
                    break
                if k == M - 1:
                    res = 'Yes'

    print(res)



main()

Solution (Python):
import sys

import numpy as np

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = np.full((N, N), "", dtype=str)
    for i in range(N):
        A[i] = list(input().rstrip())
    B = np.full((M, M), "", dtype=str)
    for i in range(M):
        B[i] = list(input().rstrip())

    ans = "No"
    L = N - (M - 1)
    for i in range(L):
        for j in range(L):
            if np.all(A[i:i + M, j:j + M] == B):
                ans = "Yes"
    print(ans)


if __name__ == "__main__":
    main()

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

flag = [[True for j in range(n)] for i in range(n)]
for i in range(n):
    for j in range(n):
        for k in range(min(m, i + 1)):
            for l in range(min(m, j + 1)):
                if a[i][j] != b[k][l]:
                    flag[i - k][j - l] = False

for i in range(n-m+1):
    for j in range(n-m+1):
        if flag[i][j]:
            print("Yes")
            exit()

print("No")

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

al = [list(input()) for _ in range(n)]
bl = [list(input()) for _ in range(m)]

def same(h,w):
    for hi in range(m):
        for wi in range(m):
            if al[h+hi][w+wi]!=bl[hi][wi]:
                return False
    return True


for hi in range(n-m+1):
    for wi in range(n-m+1):
        if same(hi,wi):
            print("Yes")
            exit()
print("No")

Solution (Python):
N, M = map(int, input().split())
image = []
template = []
ans = "No"

for _ in range(N):
    row = list(input())
    image.append(row)

for _ in range(M):
    row = list(input())
    template.append(row)

for h in range(0, N-(M-1)):
    for w in range(0, N-(M-1)):
        if image[h][w] == template[0][0]:
            flag = True
            for h2 in range(M):
                for w2 in range(M):
                    if image[h+h2][w+w2] != template[h2][w2]:
                        flag = False
                        break
            if flag == True:
                ans = "Yes"
                break

print(ans)

Solution (Python):
def inc(y,x):
    f = True
    for i in range(m):
        for j in range(m):
            if B[i][j] != A[y+i][x+j]:
                f = False
                break
        if not f:break
    return f
n,m = map(int,input().split())
A =[]
for i in range(n):
    A.append(input())
B = []
for i in range(m):
    B.append(input())

for y in range(n-m+1):
    for x in range(n-m+1):
        if inc(y,x):
            print("Yes")
            exit()
print("No")

Solution (Python):

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

isIncluding = False

for a_row in range(n):
    for a_column in range(n):

        if a[a_row][a_column] == b[0][0]:

            isExact = True
            for b_row in range(m):
                for b_column in range(1, m):
                    if a_row + b_row > n - 1 or a_column + b_column > n - 1:
                        isExact = False
                        break

                    if b[b_row][b_column] != a[a_row + b_row][a_column + b_column]:
                        isExact = False
                        break

                if not isExact:
                    isExact = True
                    break
            else:
                isIncluding = True
                break

        if isIncluding:
            break
            
    if isIncluding:
        break

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

Solution (Python):
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)])
flug = 0

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):
            flug =1

ans = 'Yes' if flug else 'No'
print(ans)

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

def match(y,x):
    result = True
    for i in range(m):
        for j in range(m):
            if a[y+i][x+j] != b[i][j]:
                result = False
    return result

flg = False
for i in range(n-m+1):
    for j in range(n-m+1):
        if match(i,j):
            flg = True

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

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

c = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        c = 0
        for x in range(m):
            for y in range(m):
                if a[i+x][j+y] == b[x][y]:
                    c += 1
            
        if c == m**2:
            break
    
    if c == m**2:
        break

if c == m**2:
    print('Yes')

else:
    print('No')

Solution (Python):
n, m, *d = open(0).read().split()
n, m = int(n), int(m)
r = range(n - m + 1)
print(["No","Yes"][any(d[n:] == [t[j:j+m] for t in d[i:i+m]] for i in r for j in r)])

Solution (Python):
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

n, m = inpl()
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):
        A1 = [a[j:j+m] for a in A[i:i+m]]
        if A1 == B:
            print('Yes')
            exit()
print('No')

Solution (Python):
n,m=[int(i) for i in input().split()]
A=[]
for i in range(n):
    A.append(list(input()))
B=[]
for i in range(m):
    B.append(list(input()))

def choise(x,y):
    C=[]
    for i in range(x,x+m):
        C.append(A[i][y:y+m])
    return C

ans=0
for x in range(n-m+1):
    for y in range(n-m+1):
        if choise(x,y)==B:
            ans+=1
if ans==0:
    print("No")
else:
    print("Yes")

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

B = [list(input()) for i in range(M)]
temp = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        for row in range(M):
            for col in range(M): 
                if A[i+row][j+col] == B[row][col]:
                    temp +=1
                    if temp == M*M:
                        print('Yes')
                        exit()
                    continue
                else:
                    temp = 0
                    break
     
            
print('No')

Solution (Python):
N,M=map(int,input().split())
A=[input().rstrip() for i in range(N)]
B=[input().rstrip() for i in range(M)]
for i in range(N-M+1):
  for j in range(N-M+1):
    f=True
    for k in range(M):
      if A[i+k][j:j+M]!=B[k]:
        f=False
        break
    if f:
      print("Yes")
      exit()
print("No")

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

Solution (Python):
from sys import exit

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

def valid(i, j):
    for a, b in zip(A[i:i+M], B):
        if a[j:j+M] == b:
            continue
        else:
            return False
    return True
if N > M:
    for i in range(N-M):
        for j in range(N-M):
            if valid(i, j):
                print("Yes")
                exit()
else:
    if valid(0,0):
        print("Yes")
        exit()
print("No")

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

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

    for i in range(N-M+1):
        for j in range(N-M+1):
            ok = 1
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        ok = 0
            if ok:
                print('Yes')
                exit()
    print('No')


if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
  a.append(str(input()))
for _ in range(m):
  b.append(str(input()))
ans = False
for i in range(n-m+1):
  for j in range(n-m+1):
    match = True
    for k in range(m):
      
      if a[i+k][j:j+m] != b[k]:
        match = False
        break
    if match:
      ans = True
      break
  if ans: break
if ans: print('Yes')
else: print('No')

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
a = [input() for i in range(n)]
b = [input() for j in range(m)]
flag = True
for i in range(n - m + 1):
    for j in range(n - m + 1):
        for k in range(m):
            if a[k + i][j:j + m] != b[k]:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
        flag = True
print('No')

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

image = []
template = []

for _ in range(N):
  image.append([c for c in input()])

for _ in range(M):
  template.append([c for c in input()])
  

def is_match(a, b):
  for i in range(M):
    for j in range(M):
      if template[i][j] != image[a + i][b + j]:
        return False
  return True

def solve():
  for i in range(0, N - M + 1):
    for j in range(0, N - M + 1):
      if is_match(i, j):
        return True
  return False

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

Solution (Python):
a, b = map(int, input().split())

A = []
for i in range(a):
    A.append(list(input()))
B = []
for i in range(b):
    B.append(list(input()))
f = 0
for i in range(a - b + 1):
    for j in range(a - b + 1):
        if A[i][j] == B[0][0]:
            ans = 0
            for k in range(b):
                for l in range(b):
                    if A[i+k][j+l] == B[k][l]:
                        continue
                    else:
                        ans = 1
            if ans == 0 and f == 0:
                print("Yes")
                f = 1
                break
if f == 0:
    print("No")