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=[[] for i in range(n)]
b=[[] for i in range(m)]
f=0
for i in range(n):
    
    a[i]=list(input())
for i in range(m):
    b[i]=list(input())
for i in range(n-m+1):
    for j in range(n-m+1):
        ans=0
        for x in range(m):
            for y in range(m):
                if b[x][y]==a[x+i][y+j]:                 
                    ans+=1
        if ans==m*m:
            f=1
print("Yes" if f==1 else "No")

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

ans = "No"

for up in range(N-M+1):
  for left in range(N-M+1):
    flag = True
    for m1 in range(M):
      for m2 in range(M):
        if A[up+m1][left+m2] != B[m1][m2]:
          flag = False
    if flag == True:
      ans = "Yes"
      break
print(ans)

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):
        bol = 1
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    bol = 0
        if bol:
            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)]
C = [[]*M for _ in range(N)]

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

def a():
    for i in range(N-M+1):
        for j in range(N-M+1):
            if match(i,j):return "Yes"
    return "No"

print(a())

Solution (Python):
N,M=map(int,input().split())
A = [str(input()) for _ in range(N)]
B = [str(input()) for _ in range(M)]
k=N//M + N%M
def macthing(y,x):
  flag=0
  for p in range(M):
    if A[y+p][x:x+M]!=B[p]:
      flag=1
      break
  if flag==0:
    return True
  else:
    return False

for i in range(k):
  for j in range(k):
    if macthing(i,j):
      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)]
k=N//M + N%M
def macthing(y,x):
  flag=0
  for p in range(M):
    if A[y+p][x:x+M]!=B[p]:
      flag=1
      break
  if flag==0:
    return True
  else:
    return False
    
for i in range(k):
  for j in range(k):
    if macthing(i,j):
      print('Yes')
      exit()
print('No')

Solution (Python):
N,M=map(int,input().split())
A=[0]*N
B=[0]*M
for i in range(N):
  A[i]=str(input())
for i in range(M):
  B[i]=str(input())
k=N//M + N%M

def macthing(y,x):
  flag=0
  for p in range(M):
    if A[y+p][x:x+M]!=B[p]:
      flag=1
      break
  if flag==0:
    return True
  else:
    return False

for i in range(k):
  for j in range(k):
    if macthing(i,j):
      print('Yes')
      exit()
print('No')

Solution (Python):
import math
N,M=map(int,input().split())
A=[0]*N
B=[0]*M
for i in range(N):
  A[i]=str(input())
for i in range(M):
  B[i]=str(input())
k=math.ceil(N/M)

def macthing(y,x):
  flag=0
  for p in range(M):
    if A[y+p][x:x+M]!=B[p]:
      flag=1
      break
  if flag==0:
    return True
  else:
    return False

for i in range(k):
  for j in range(k):
    if macthing(i,j):
      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)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if all(b[k] == a[i + k][j:j + m] for k in range(m)):
            print("Yes")
            exit()
print("No")

Solution (Python):


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

for i in range(n-m+1):
    ok = True
    for j in range(n-m+1):
        ok = True
        for p in range(m):
            for q in range(m):
                if b[p][q] != a[i+p][j+q]:
                    ok = False
                    break
        if ok: 
            print('Yes')
            exit()

print('No')

Solution (Python):
def input_li():
    return list(map(int, input().split()))

def input_int():
    return int(input())

N, M = input_li()
A_LI = []
B_LI = []
for _ in range(N):
    A_LI.append(input())
for _ in range(M):
    B_LI.append(input())
for i in range(N - M + 1):
    for j in range(N - M + 1):
        is_ok = True
        for col in range(M):
            for row in range(M):
                if B_LI[col][row] != A_LI[i + col][j + row]:
                    is_ok = False
                    break
            if not is_ok:
                break
        if is_ok:
            print('Yes')
            exit()
print('No')

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

for _ in range(m):
  b = input()
  for i in a:
    if i.find(b) >= 0: break
    print("No")
    exit()
    
print("Yes")

Solution (Python):
from itertools import accumulate
N, M = map(int, input().split())

A = [[0 for _ in range(N + 1)]]
for i in range(N):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    A.append(rows)
B = [[0 for _ in range(M + 1)]]
for i in range(M):
    text = list(input())
    rows = [0]
    for j, char in enumerate(text):
        if char == '
            rows.append(rows[j] + 1)
        else:
            rows.append(rows[j])
    B.append(rows)


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

Solution (Python):
def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(list(input().rstrip()) for i in range(n))
    B = list(list(input().rstrip()) for i in range(m))
    A = np.array(A)
    B = np.array(B)
    
    for i in range(n-m+1):
        for j in range(n-m+1):
            a_b = A[i:i+m,j:j+m]
            if (a_b==B).all():
                print('Yes');exit()
    print('No')
    
if __name__=='__main__':
    main()

Solution (Python):
def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(list(input().rstrip()) for i in range(n))
    B = list(list(input().rstrip()) for i in range(m))
    A = np.array(A)
    B = np.array(B)
    
    for i in range(n-m+1):
        for j in range(n-m+1):
            a_b = A[i:i+m,j:j+m]
            if (a_b==B).all():
                print('Yes');exit()
    print('No')
    
if __name__=='__main__':
    main()

Solution (Python):
def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(list(input().rstrip()) for i in range(n))
    B = list(list(input().rstrip()) for i in range(m))
    A = np.array(A)
    B = np.array(B)
    
    for i in range(n-m+1):
        for j in range(n-m+1):
            a_b = A[i:i+m,j:j+m]
            if (a_b==B).all():
                print('Yes');exit()
    print('No')
    
if __name__=='__main__':
    main()

Solution (Python):
def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(list(input().rstrip()) for i in range(n))
    B = list(list(input().rstrip()) for i in range(m))
    A = np.array(A)
    B = np.array(B)
    
    for i in range(n-m+1):
        for j in range(n-m+1):
            a_b = A[i:i+m,j:j+m]
            if (a_b==B).all():
                print('Yes');exit()
    print('No')
    
if __name__=='__main__':
    main()

Solution (Python):
def main():
    import sys
    import numpy as np
    input = sys.stdin.readline
    n,m = map(int,input().split())
    A = list(list(input().rstrip()) for i in range(n))
    B = list(list(input().rstrip()) for i in range(m))
    A = np.array(A)
    B = np.array(B)
    
    for i in range(n-m+1):
        for j in range(n-m+1):
            a_b = A[i:i+m,j:j+m]
            if (a_b==B).all():
                print('Yes');exit()
    print('No')
    
if __name__=='__main__':
    main()

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)]


def serch(x0, y0):
  for i in range(M):
    for j in range(M):
      if x0+i >= N or y0+j >= N:
        return False
      if A[x0+i][y0+j] != B[i][j]:
        return False
  return True

if M > N:
  print('No')
  exit()


for x in range(N):
  for y in range(N):
    if not serch(x,y):
      continue
    else:
      print('Yes')
      exit()
print('No')

Solution (Python):
n, m = map(int, input().split())
al = []
bl = []

for _ in range(n):
    row = list(input())
    al.append(row)

for _ in range(m):
    row = list(input())
    bl.append(row)

for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        ok_flag = True
        for y in range(0,m):
            for x in range(0,m):
                if al[i+y][j+x] != bl[y][x]:
                    ok_flag = False
        if ok_flag:
            print('Yes')
            exit()
else:
    print('No')

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,m = readInts()
A = [list(input()) for _ in range(n)]
B = [list(input()) for _ in range(m)]
def search(j,i):
    for k in range(m):
        for s in range(m):
            if A[j+k][i+s] != B[k][s]:
                return False
            else:
                continue
    return True
flag = False
for i in range(n-m+1):
    for j in range(n-m+1):
        if A[j][i] == B[0][0]:
            if search(j,i):
                print('Yes')
                exit()
print('No')

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

ans = "No"
for i in range(N-(M-1)):
  n = -1
  c = 0
  for j in range(M):
    if B[j] in A[i+j]:
      if n < 0:
        n = A[i + j].index(B[j])
        c += 1
      else:
        if B[j] in A[i + j][n: n + b + 1]:
          c += 1
  if c == M:
    ans = "Yes"
print(ans)

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

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def tm(a, b, hi, wi):
	lb=len(b[0])
	for i, bi in enumerate(b):
		if a[hi+i][wi: wi+lb] != bi:
			return False
	return True
	


def main():
	
	n, m = tin()
	
	al=[input() for _ in range(n)]
	bl=[input() for _ in range(m)]
	for hi in range(n-m+1):
		for wi in range(n-m+1):
			if tm(al, bl, hi, wi):
				return 'Yes'
	return 'No'
	
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
n,m=map(int,input().split())
s1=[input() for _ in range(n)]
s2=[input() for _ in range(m)]
ans='No'
for i in range(n-m+1):
  for j in range(n-m+1):
    flg=0
    for k in range(m):
      if s1[j+k][i:i+m]==s2[k]:
        flg+=1
    if flg==m:
      ans='Yes'
print(ans)

Solution (Python):
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):
        wi = [a[w:w+m] for a in A[h:h+m]]
        if wi == B:
            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)]

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

print('No')

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    for row in range(n - m + 1):
        for col in range(n - m + 1):
            cur = [a[r][col:col + m] for r in range(row, row + m)]
            if cur == b:
                return print("Yes")

    print("No")


if __name__ == '__main__':
    main()

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

for i in range(N-M+1): 
  for j in range(N-M+1): 
    Flag = True
    for p in range(M):
      for q in range(M):
        
        if A[i+p][j+q] != B[p][q]:
          Flag = False
    if Flag:
      print("Yes")
      exit()
print("No")

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
As = [list(input()) for _ in range(N)]
Bs = [list(input()) for _ in range(M)]

def check(i, j):
    for h in range(M):
        for w in range(M):
            if As[i+h][j+w]!=Bs[h][w]:
                return False
    return True

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

Solution (Python):
N,M = map(int,input().split())
A = []
for _ in range(N):
    A.append(input().strip())
B = []
for _ in range(M):
    B.append(input().strip())
flag = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        ind = 0
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l]!=B[k][l]:
                    ind = 1
                    break
            if ind==1:break
        if ind==0:
            flag = 1
    if flag==1:break
if flag==1:
    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)]
ok=0
for i in range(n-m+1):
  for k in range(n-m+1):
    if B[0]==A[i][k:k+m]:
      for j in range(i,i+m):
        if B[j-i]!=A[j][k:k+m]:
          break
      else:
        ok=1
print("Yes" if ok==1 else "No")

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

if __name__ == "__main__":
    main()

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


def match(i0, i1):
    for j0 in range(m):
        for j1 in range(m):
            if s0[i0 + j0][i1 + j1] != s1[j0][j1]:
                return False
    return True


def answer():
    for i0 in range(n - m + 1):
        for i1 in range(n - m + 1):
            if match(i0, i1):
                return True
    return False


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

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    A, B = [], []
    for _ in range(N):
        A.append(input())
    for _ in range(M):
        B.append(input())
    for i in range(N-M+1):
        for j in range(N-M+1):
            matches = True
            for i0 in range(i, i+M):
                for j0 in range(j, j+M):
                    if A[i0][j0] != B[i-i0][j-j0]:
                        matches = False
                        break
                if not matches:
                    break
            if matches:
                return 'Yes'
    return 'No'


if __name__ == '__main__':
    print(solve())

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

nlis = [list(input()) for _ in range(n)]
mlis = [list(input()) for _ in range(m)]

f = 0

for i in range(n):
    for j in range(n):
        if i+m-1 >=n or j+m-1 >=n:
            continue

        flag = 1
        for k in range(m):
            for l in range(m):
                if nlis[i+k][j+l] != mlis[k][l]:
                    flag = 0
        
        if flag:
            f = 1

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

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  

N,M = MI()
A = [LS2() for _ in range(N)]
B = [LS2() for _ in range(M)]

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

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

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

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

for i in range(N):
    for j in range(N):
        if check(i, j):
            print("Yes")
            exit()
print("No")

Solution (Python):
from sys import exit

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

print('No')

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

ans = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        C = [A[k][i:i+M] for k in range(j, j+M)]
        if B == C:
            ans = 'Yes'
print(ans)

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):
        tmp=["" for i in range(m)]
        for k in range(m):
            for r in range(m):
                tmp[k]+=A[i+k][j+r]
        
        if tmp == B:
            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)]
for i in range(N-M+1):
  for j in range(len(A[i])-len(B[0])+1):
    if B[0][0]==A[i][j]:
      flag=True
      p=i
      for k in range(M):
        if not B[k]==A[p][j:j+len(B[k])]:
          flag=False
          break
        p+=1
      if flag:
        print('Yes')
        exit()
print('No')

Solution (Python):
n,m=map(int,input().split())
n_pict=[]
m_pict=[]
for _ in range(n):
  n_pict.append(input())
for _ in range(m):
  m_pict.append(input())
  
for y in range(n-m+1):
  for x in range(n-m+1):
    found=True
    for a in range(m):
      if m_pict[a]!=n_pict[y+a][x:x+m]:
        found=False
        break
    if found:
      print("Yes")
      exit()
print("No")

Solution (Python):





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()))

judge = False
for offset_i in range(n - m + 1):
    for offset_j in range(n - m + 1):

        flg = 0
        for i in range(m):
            for j in range(m):
                if a[i + offset_i][j + offset_j] == b[i][j]:
                    flg += 1

        if flg == m * m:
            judge = True
            

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

Solution (Python):






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





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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    A = [0] * N
    for i in range(N):
        A[i] = readline().strip()
    B = [0] * M
    for i in range(M):
        B[i] = readline().strip()

    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
                        break
                if not ok:
                    break
            if ok:
                print('Yes')
                return

    print('No')
    return


if __name__ == '__main__':
    main()

Solution (Python):
a,b=map(int,input().split())
ListA = []
for i in range (a):
  ListA.append(input())
ListB = []
for i in range (b):
  ListB.append(input())
flag = False
  
def checkAB(List1,List2,aa,bb):
  for k in range(b):
    if List1[aa+k][bb:bb+b] != List2[k]:
      return False
  return True
  
for i in range(a-b+1):
  for j in range(a-b+1):
    if checkAB(ListA,ListB,i,j):
      flag = True
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
n,m=map(int,input().split())
a=[]
b=[]
for _ in range(n):
    x=[1 if s=='
    a.append(x)

for _ in range(m):
    x=[1 if s=='
    b.append(x)

for h in range(n-m+1):
    for w in range(n-m+1):
        tmpa=[a[x][w:w+m] for x in range(h,h+m)]
        if tmpa==b:
            print('Yes')
            exit()
print('No')

Solution (Python):
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  a = str(input())
  A.append(a)
for i in range(M):
  b = str(input())
  B.append(b)
  
flag = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      k = 1
      while k < M:
        if A[i+k][j:j+M] == B[k]:
          k += 1
        else:
          break
      if k == M:
        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(len(A[0])-len(B[0])+1):
        l=[]
        for k in range(M):
            l.append(A[i+k][j:j+M])
        if l==B:print('Yes');exit()
print('No')

Solution (Python):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    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 = False
            for k in range(m):
                for l in range(m):
                    if a[i+k][j+l] != b[k][l]:
                        flag = True
                        break
                if flag:
                    break
            if not flag:
                break
        if not flag:
            break
    if not flag:
        print('Yes')
    else:
        print('No')
                
    

            

    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    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):
                for l in range(m):
                    if a[i+k][j+l] != b[k][l]:
                        flag = False
                        break
                else:
                    continue
                break
            if flag:
                break
        else:
            continue
        break
    if flag:
        print("Yes")
    else:
        print('No')
                
    

            

    
if __name__ == '__main__':
    main()

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

d = n - m + 1
flg = False
for i in range(d):
    for j in range(d):
        if a[i][j : j + m] == b[0]:
            for k in range(1, m):
                if a[i + k][j : j + m] != b[k]:
                    break
            else:
                print("Yes")
                flg = True
                break
    if flg:
        break
else:
    print("No")

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush

sys.setrecursionlimit(10**7)







def run():
    N,M = map(int, sysread().split())
    A, B = [],[]
    for i in range(N):
        A.append(input())
    for i in range(M):
        B.append(input())
    
    b = B[0]
    collection = []
    for i in range(N-M+1):
        a = A[i]
        for j in range(N-M+1):
            for k in range(M):
                if a[j+k] != b[k]:break
            collection.append((i,j))

    for start in collection:
        i, j = start
        breaked = False
        for x in range(M):
            if A[i+x][j:j+M] != B[x]:
                breaked = True
                break
        if not breaked:
            print("Yes")
            return None
    print("No")




if __name__ == "__main__":
    run()

Solution (Python):
import sys


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

for i in range(N-M+1):
  for j in range(N-M+1):
    As=[x[i:i+M] for x in A[j:j+M]]
    if B==As:
      print('Yes')
      sys.exit()
print('No')

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

H = N - M + 1
flag = 'No'

for i in range(H):
    for j in range(H):
        cnt = 0
        for d in range(M):
            if B[d] != A[i+d][j:j+M]:
                break
            cnt += 1
        if cnt == M:
            flag = 'Yes'
            break
    else:
        continue
    break

print(flag)

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):
        cnt = 0
        for k in range(m):
            if a[i+k][j:j+m] == b[k]:
                cnt += 1
            if cnt == m:
                print("Yes")
                exit()
print("No")

Solution (Python):
import numpy as np
N,M = list(map(int,input().split()))

A=[]
B=[]
for n in range(N):
    A_ = list(input())
    A.append(A_)
    
for m in range(M):
    B_ = list(input())
    B.append(B_)
    
B=np.array(B)

ans='No'
for n1 in range(N-M+1):
    for n2 in range(N-M+1):
        check = np.array(A)[n1:n1+M,n2:n2+M]
        c=np.unique(check == B)
        
        if False not in set(c):
            ans='Yes'
            break
            
print(ans)

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

if n == m:
    print ("Yes") if A == B else print ("No")
    exit ()

for A_i in range(len(A)):
    for a_i in range(len(A[A_i])):
        if A[A_i][a_i] == B[0][0]:
            if m <= n-A_i and m <= n-a_i:
                tmp = []
                for i in range(A_i,A_i+m):
                    tmp_l = []
                    for j in range(a_i,a_i+m):
                        tmp_l.append(A[i][j])
                    tmp.append(tmp_l)
                if B == tmp:
                    print ("Yes")
                    exit ()
print ("No")