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):
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return












from fractions import gcd












from queue import Queue

























def crange(a, b, i):
    return range(a, b + 1, i)


def main():
    n, m = map(int, input().strip().split())
    a = [input().strip() for _ in range(n)]
    b = [input().strip() for _ in range(m)]
    n, m = (lambda x, y: (x - 1, y - 1))(n, m)
    eprint("n,m ", end=": ")
    eprint(n,m)
    
    ii, jj, colx, rowx = 0, 0, 0, 0
    for i in crange(0, n - m, 1):
        for j in crange(0, n - m, 1):
            failure_flag = 0
            for col in crange(0, m, 1):
                for row in crange(0, m, 1):
                    if a[i+col][j+row] != b[col][row]:
                        failure_flag = 1
                        ii, jj, colx, rowx = i, j, col, row
            if failure_flag == 0:
                print("Yes")
                eprint("ii,jj,colx,rowx ", end=": ")
                eprint(ii, jj, colx, rowx)
                return
    print("No")
    eprint("ii,jj,colx,rowx ", end=": ")
    eprint(ii, jj, colx, rowx)
    return


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)]
for i in range(n-m+1):
  row=a[i]
  if b[0] in row:
    j=row.find(b[0])
    c=0
    for k in range(i,i+m):
      if a[k][j:j+m]==b[k-i]:
        c+=1
      else:
        break
    if c==m:
      print("Yes")
      exit()
print("No")

Solution (Python):


def main():
    n, m = map(int, input().split())
    a = [input() for _ in range(n)]
    b = [input() for _ in range(m)]
    flag = False

    for i in range(n-m+1):
        for j in range(n-m+1):
            na = []
            for l in a[i:i+m]:
                na.append(l[j:j+m])
                if na == b:
                    flag = True
                

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

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



if m==1:
    for i in range(n):
        if b[0] in a[i]:
            print('Yes')
            exit()

    print('No')
    exit()
if m==n:
    if a==b:
        print('Yes')
        exit()
    else:
        print('No')
        exit()

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

Solution (Python):
def find_indices(a, b, L):
    
    return [i for i in range(L) if a[i:].startswith(b)]

def solve():
    N,M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    idx = 0
    start_pos = {}
    for S_a in A:
        indices = set(find_indices(S_a, B[idx], N))
        if not start_pos:
            start_pos = indices
        else:
            start_pos = start_pos&indices
        
        if start_pos:
            idx += 1
        else:
            start_pos = {}
            idx = 0
            
        if idx == M:
            break
    
    print('Yes' if start_pos else 'No')
    
solve()

Solution (Python):
def check():
    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):
            flag = True
            for k in range(M):
                if A[i+k][j:j+M] != B[k]:
                    flag = False
            if flag:
                return 'Yes'
    return 'No'
print(check())

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

for i in range(0, N-M+1):
    pos = A[i].find(B[0])
    if pos >= 0:
        for j in range(1, M):
            if A[i+j][pos:pos+M] != B[j]:
                break
        else:
            print('Yes')
            break
else:
    print('No')

Solution (Python):
a,b = map(int,input().split())
l= []
L = []
for i in range(a):
    t= input()
    l.append(t)
for i in range(b):
    t = input()
    L.append(t)
f = 'No'
for i in range(a-b+1):
    for j in range(a-b+1):
        s = 0
        for I in range(b):
            for J in range(b):
                if l[i+I][j+J] == L[I][J] :s+=1
        if s==b**2:f='Yes'
print(f)

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

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

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

def func(base, target):
   for i in range(n-m+1):
      check = base[i:i+m]
      for j in range(n-m+1):
         check2 = [line[j:j+m] for line in check]
         if check2 == target:
            return print('Yes')
   return print('No')

func(a,b)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, m = list(map(int, input().strip().split()))
    a = []
    b = []
    for i in range(n):
        a.append(input().strip())
    for i in range(m):
        b.append(input().strip())
    for i in range(n):
        if i + m > n:
            break
        for j in range(n):
            if j + m > n:
                break
            flag = False
            for p in range(m):
                for q in range(m):
                    if b[p][q] != a[i+p][j+q]:
                        flag = True
                        break 
            if flag:
                continue
            else:
                print('Yes')
                return
    print('No')

if __name__ == '__main__':
    main()

Solution (Python):
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()))
num=n-(m-1)
ok=0 
def check(y,x):
    c=1 
    for i in range(m):
        for j in range(m):
            if a[y+i][x+j]!=b[i][j]:
                c=0
                break
        if c==0:
            break
    return c
for i in range(num):
    for j in range(num):
        
        if check(i,j)==1:
            ok=1
            break
    if ok==1:
        break
            
print("Yes" if ok==1 else "No")

Solution (Python):
N, M = [int(i) for i in 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 ii in range(M):
            for jj in range(M):
                if A[i+ii][j+jj] != B[ii][jj]:
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Solution (Python):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
A=[input().strip() for _ in range(n)]
B=[input().strip() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        flg=True
        for k in range(m):
            
            if A[i+k][j:j+m]!=B[k]:
                flg=False
        if flg:
            print("Yes")
            exit()

print("No")

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

a_mat = [input() for _ in range(N)]
b_mat = ''.join([input() for _ in range(M)])


def to_vectors(mat, size=M):
    vectors = []
    for h in range(N-M+1):
        for w in range(N-M+1):
            tmp = [mat[h+i][w:w+M] for i in range(M)]
            vectors.append(''.join(tmp))
    return vectors


if b_mat in to_vectors(a_mat, M):
    print('Yes')
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)]
def all_true(i,j):
    global a,b
    for k in range(i,i+m):
        for l in range(j,j+m):
            if a[k][l]!=b[k-i][l-j]:
                return False
    return True
f=0
for i in range(n-m+1):
    for j in range(n-m+1):
        if all_true(i,j):
            f=1
            break
    if f==1:
        print("Yes")
        break
else:
    print("No")

Solution (Python):
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')

Solution (Python):
[n,m]=list(map(int,input().split()))
alist=[]
blist=[]
counter=0
for i in range(n):
    alist.append(list(input()))
for i in range(m):
    blist.append(list(input()))
clist=[]
if n!=m:
    for i in range(n-m):
        for j in range(n-m):
            for k in range(m):
                kari=[]
                for l in range(m):
                    kari.append(alist[i+k][j+l])
                clist.append(kari)
            
            if blist==clist:
                counter=1
                break
            clist=[]

else:
    if alist==blist:
        counter=1

if counter==1:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
A = []
for _ in range(N):
    A.append(list(input().rstrip()))
B = []
for _ in range(M):
    B.append(list(input().rstrip()))
n = len(A[0])
m = len(B[0])
def search(point):
    x, y = point
    for i in range(M):
        if y > N - 1:
            return 0
        a = A[y][x:x + m]
        if a != B[i]:
            return 0
        y += 1
    return 1
for i in range(N):
    for j in range(n):
        if search([i, j]):
            print("Yes")
            sys.exit()
print("No")

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline









N, M, = map(int, input().split())
a = [list(input().strip())  for _ in range(N)]
b = [list(input().strip())  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[i + k][j + l] != b[k][l]:
                    f = False
        if f:
            print("Yes")
            exit()

print("No")

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

A = []
for i in range(N):
    tmp = str(input())
    A.append(tmp)
    
B = []
for i in range(M):
    tmp = str(input())
    B.append(tmp)
    
ans = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        if [a[j:j+M] for a in A[i:i+M]] == B:
            ans = "Yes"

print(ans)

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

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

bList = []
for j in range(m):
  bList.append(input())

for k in range(n-(m-1)):
  aIMatch = aList[k].find(bList[0])
  aICount = aList[k].count(bList[0])
  for ct in range(aICount):
 
    sucFlag = True 
    for l in range(1,m):
      aNMatch = aList[k+l].find(bList[l],aIMatch)
      if not(aNMatch >= 0 and aIMatch == aNMatch):
        sucFlag = False
        break
    if sucFlag:
      print("Yes")
      exit(0)
    aIMatch = aList[k].find(bList[0],aIMatch+1)

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

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

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

print("No")

Solution (Python):
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()))

k=N-M+1
ans=False

for i in range(k):
    for j in range(k):
        flg=True
        
        for p in range(M):
            for q in range(M):
                if A[i+p][j+q] != B[p][q]:
                    flg=False
                    
        ans=flg
        if ans:
            break
    if ans:
        break

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

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

for i in range(m):
  b.append([i for i in input()])
  
for i in range(n-m+1):
  flg=True
  if b_flg:
    break
  for j in range(n-m+1):
    if not flg:
      break
    for k in range(m):
      if not flg:
        break
      for l in range(m):
        if a[i+k][j+l]==b[k][l]:
          flg=True
        else:
          flg=False
    if flg:
      b_flg=True
      break
if b_flg:
  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)]

flag = False

for i in range(n-m+1):
    for j in range(n-m+1):
        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:
            flag = True
            break
    if flag:
        break
print("Yes" if flag else "No")

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

k = (N-1)-(M-1)+1

def judge(x, y):
    for i in range(M):
        for j in range(M):
            if not(A[x+i][y+j]==B[i][j]):
                return False
    return True


for i in range(k):
    for j in range(k):
        if judge(i, j):
            print("Yes")
            quit()

print("No")

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

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


def f(i, j):
  for k in range(M):
    for l in range(M):
      if A[i+k][j+l] != B[k][l]:
        return False
  return True

def slv():
  for i in range(N-M+1):
    for j in range(N-M+1):
      if f(i, j):
        return 'Yes'
  return 'No'
print(slv())

Solution (Python):
n,m = map(int,input().split())
a = [str(input()) for _ in range(n)]
b = [str(input()) for _ in range(m)]
flag = False
for l in range(n-m+1):
    for k in range(n-m+1):
        cnt = 0
        for i in range(m):
            for j in range(m):
                if a[k+i][j+l]==b[i][j]:
                    cnt += 1
            if cnt==m**2:
                flag = True
                break
        if flag:
            break
    if flag:
        break
print('Yes' if flag else 'No')

Solution (Python):
from itertools import product

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

b = "".join(B)

ans = "No"
for i, j in product(range(N - M + 1), repeat=2):
    a = "".join(["".join(x[j:j + M]) for x in A[i:i + M]])
    if a == b:
        ans = "Yes"
        break
print(ans)

Solution (Python):


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

a = []
b = []

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



upperMatched = []

b0 = b[0]
for i in range(n-m+1):
    for j in range(n-m+1):
        
        
        
        if b0 == a[j][i:i+m]:
            
            
            upperMatched.append([i,j])
            



if len(upperMatched) == 0:
    print("No")
    exit()



for uM in upperMatched:
    isMatched = True
    i = uM[0]
    j = uM[1]

    for r in range(1, m):
        
        
        if b[r] == a[i+r][j:j+m]:
            pass
        else:
            isMatched = False
    if isMatched:
        print("Yes")
        exit()
    else:
        pass

print("No")

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

N, M = MAP()
grid1 = build_grid(N, N, '', str, space=0)
grid2 = build_grid(M, M, '', str, space=0)

def check(i, j):
    for k in range(i, i+M):
        for l in range(j, j+M):
            if grid1[k][l] != grid2[k-i][l-j]:
                return False
    return True

for i in range(N-M+1):
    for j in range(N-M+1):
        if check(i, j):
            Yes()
            exit()
No()

Solution (Python):
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):
    for j in range(m-n+1):
        for k in range(n):
            if b[k] != a[i+k][j:j+n]:
                break
        else:
            flag = True
if flag:
    print('Yes')
else:
    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):
        ans = 0
        for ii in range(m):
            for jj in range(m):
                if b[ii][jj] == a[i+ii][j+jj]:
                    ans += 1
        if ans == m*m:
            print("Yes")
            exit()

print("No")

Solution (Python):
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()

flag = False
for i in range(n-m+1):
    if flag: break
    for j in range(n-m+1):
        suba = a[i:i+m]
        for k in range(len(suba)):
            suba[k] = suba[k][j:j+m]
        if suba == b:
            flag = True
            break

if flag:
    print("Yes")
else:
    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
                    break
            if not flag:
                break
        if flag:
            print('Yes')
            break
    if flag:
        break

if not flag:
    print('No')

Solution (Python):
import sys
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a1 = input()
    A.append(a1)
for _ in range(M):
    b1 = input()
    B.append(b1)
    
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]:
                pass
            else:
                break
            if k == M-1:
                print("Yes")
                sys.exit()
print("No")

Solution (Python):

N, M = map(int, input().split())
A, B = [], []
for i in range(N):
    tmp = input()
    A.append(tmp[:])
for i in range(M):
    tmp = input()
    B.append(tmp[:])
for r in range(len(A[0]) - len(B[0]) + 1):
    for i in range(N - M + 1):
        cnt = 0
        for j in range(i, M+i):
            
            if A[j][r:r+len(B[0])] == B[j-i]:
                cnt += 1
        if cnt == M:
            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
                    break
            if not flag:
                break
        if flag:
            print('Yes')
            break
    if flag:
        break

if not flag:
    print('No')

Solution (Python):
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
ans = False
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
                    break
            if not flag:
                break
        if flag:
            ans = True
            break
    if ans:
        break
print('Yes' if ans else 'No')

Solution (Python):


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

ans = False
for i in range(N):
    for j in range(N):
        if i + M - 1 >= N or j + M - 1 >= N:
            continue
        match = True
        for y in range(M):
            for x in range(M):
                if A[i + y][j + x] != B[y][x]:
                    match = False
        if match:
            ans = True

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

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

Solution (Python):
nm=list(map(int,input().split()))
a,b=[],[]
for i in range(nm[0]):
    a.append(input())
for j in range(nm[1]):
    b.append(input())

def check(i,j):
    result="match"
    for k in range(nm[1]):
        if b[k]==a[i+k][j:j+nm[1]]:
            continue
        else:
            result="unmatch"
            break
    return result

flag=0
for i in range(nm[0]-nm[1]+1):
    if flag==0:
        for j in range(nm[0]-nm[1]+1):
            if check(i,j)=="match":
                print("Yes")
                flag=1
                break
if flag==0:
    print("No")

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

A=[]
B=[]

for n in range(N):
    A.append(input())

for m in range(M):
    B.append(input())
        
if N<M:
    print("No")
    exit()

for n in range(N):
      
      
      span =[m.span() for m in re.finditer(B[0], A[n])]
      
      if span==[]:
          continue
      allgood=False
      for sp in span:
        for i in range(min(M,N)):
            if n+i>=N:
                allgood=False
                break
            
            
            if (B[i]==A[n+i][sp[0]:sp[1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

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

for oh in range(N-M+1):
    for ow in range(N-M+1):
        match = True
        for ih in range(M):
            for iw in range(M):
                if A[oh+ih][ow+iw]!=B[ih][iw]:
                    match = False
                    break
            if not match: break
        if match:
            print('Yes')
            exit()
print('No')

Solution (Python):
N,M=map(int,input().split())
la=[]
lb=[]
for i in range(N):
    la.append(input())
for i in range(M):
    lb.append(input())
f=0
for i in range(N-M+1):
    if f==1:
        break
    for j in range(N-M+1):
        if f==1:
            break
        f=0
        for k in range(M):
            for l in range(M):
                if la[i+k][j+l]!=lb[k][l]:
                    f=-1
                    break
            if f==-1:
                break

        if f!=-1:
            f=1
if f==1:
    print("Yes")
else:
    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
print("Yes" if bl else "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 h in range(M):
                        for w in range(M):
                                if A[i+h][j+w] != B[h][w]:
                                        flag = False             
                                        break
                if flag == True:
                        print("Yes")
                        exit()
print("No")

Solution (Python):

 
import math
import itertools
import sys
import copy
 

N, M = map(int, input().split())



A = []
for _ in range(N) :
  A.append(str(input()))

B = ""
for _ in range(M) :
  B += str(input())

for x in range(N-M+1) :
  for y in range(N-M+1) :
    t = ""
    for k in range(M) :
      t += (A[y+k])[x:x+M]
    
    if t == B :
      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)])

hantei = False

for i in range(N-M+1):
  for j in range(N-M+1):
    C=np.array(A[i:i+M,j:j+M])
    if (C==B).all():
      hantei = True
print('Yes' if hantei else 'No')

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

if N==M:
    f=1
    for i in range(N):
        if f==-1:
            break
        for j in range(N):
            if la[i][j]!=lb[i][j]:
                f=-1
                break
    if f==1:
        print("Yes")
    else:
        print("No")
else:
    f=0
    for i in range(N-M):
        if f==1:
            break
        for j in range(N-M):
            if f==1:
                break
            f=0
            for k in range(M):
                if f==-1:
                    break
                for l in range(M):
                    if la[i+k][j+l]!=lb[k][l]:
                        f=-1
                        break
                if k==M-1 and l==M-1 and f!=-1:
                    f=1
                    break
    if f==1:
        print("Yes")
    else:
        print("No")

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

def template_matching():
  for y in range(n-m+1):   
    for x in range(n-m+1):
      flag = True
      for yi in range(m):
        if aa[y+yi].find(bb[yi],x)-x != 0:          
          flag = False
      if flag :
        return True
  return False

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

Solution (Python):
from sys import exit

def func(i,j):
	f=True
	for x in range(M):
		for y in range(M):
			if A[i+x][j+y]!=B[x][y]:
				f=False
	return f


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

for i in range(N):
	A.append(list(map(lambda x:1 if x=='

for i in range(M):
	B.append(list(map(lambda x:1 if x=='


for i in range(N-M+1):
	for j in range(N-M+1):
		if func(i,j):
			print('Yes')
			exit()

print('No')

Solution (Python):


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

for i in range(n - m + 1):
    for j in range(n - m + 1):
        target = [["-" for _ in range(m)] for _ in range(m)]
        for y in range(m):
            for x in range(m):
                target[y][x] = a[i + y][j + x]
        if b == target:
            print("Yes")
            exit()
print("No")

Solution (Python):

import numpy as np

N,M = map(int, input().split())

a_array = []
b_array = []

for i in range(N):
    a = str(input())
    a_list = [a[i] for i in range(N)]
    a_array.append(a_list)

for i in range(M):
    b = str(input())
    b_list = [b[i] for i in range(M)]
    b_array.append(b_list)

a_nparrary = np.array(a_array)
b_nparrary = np.array(b_array)
break_flag = 0

for x in range(N-M+1):
    for y in range(N-M+1):
        sliced_a_nparray = a_nparrary[x:x+M,y:y+M]
        
        
        if (sliced_a_nparray == b_nparrary).all():
            print("Yes")
            break_flag = 1
            break
    
    if break_flag == 1:
        break
else:
    print("No")

Solution (Python):
import numpy as np
a,b = [int(i) for i in input().split()]

al = np.array([list(input()) for _ in range(a)])
bl = np.array([list(input()) for _ in range(b)])

flg  = False
for i in range(a - b + 1):
    for j in range(a - b + 1):
        if(al[i:i+b,j:j+b] == bl).all():
            flg = True
            
print('Yes' if flg else 'No')

Solution (Python):
import sys
 
stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
 
n,m = na()
ba = []
for i in range(n):
    ba.append(ns())
bb = []
for i in range(m):
    bb.append(ns())
 
for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            if ba[i+k][j:j+m] != bb[k]:
                ok = False
                break
        if ok:
            print("Yes")
            sys.exit(0)
print("No")