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().strip().split(" "))

a=[]
b=[]

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

N=0

for i in range(M):
    b.append(input())
    if(b[i] in a[i]):
        N+=1

if(N==M):
    print("Yes")
else:
    print("No")

Solution (Python):
line = input().split(" ")
n = int(line[0])
m = int(line[1])
a = []
b = []

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

for nh in range(n-m+1):
    for nw in range(n-m+1):
        for k in range(m):
            s1 = a[nh+k][nw : nw+m]
            s2 = b[k]
            if s1 != s2:
                break
        else:
            print("Yes")
            exit()

print("No")

Solution (Python):



def main():
    """Function."""
    n, m = map(int, input().split())

    pic_n, pic_m = [], []
    for _ in range(n):
        pic_n.append(list(input()))
    for _ in range(m):
        pic_m.append(list(input()))

    flag = 0
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            dum = []
            for x in range(m):
                if pic_n[i+x][j:j+m] != pic_m[x]:
                    dum.append(0)
                else:
                    dum.append(1)

            if 0 in dum:
                continue
            else:
                flag = 1
        if flag == 1:
            break

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


if __name__ == "__main__":
    main()

Solution (Python):
N,M = map(int,input().split())
nlis = []
for i in range(N):
    nlis.append(input())
mlis = []
for i in range(M):
    mlis.append(input())
k = N-M
for i in range(k+1):
    for j in range(k+1):
        l = []
        for o in range(M):
            l.append(nlis[i+o][j:j+M])
        if l == mlis:
            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)]

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

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

BL = []
for i in range(M):
	B = list(input())
	BL.append(B)

judge = "No"

for i in range(N - M + 1):
	for j in range(N - M + 1):
		c = "Yes"
		for k in range(M):
			for l in range(M):
				if AL[i + k][j + l] != BL[k][l]:
					c = "No"
					break
		if c == "Yes":
			judge = "Yes"

print(judge)

Solution (Python):
n = 0
m = 0
aa = []
bb = []


def match(y0, x0):
    global m, aa, bb
    for i, y in enumerate(range(y0, y0 + m)):
        if aa[y][x0:(x0 + m)] != bb[i]:
            return False
    return True


def main():
    global n, m, aa, bb
    n, m = map(int, input().split())
    aa = [input() for _ in range(n)]
    bb = [input() for _ in range(m)]
    for y0 in range(n - m + 1):
        for x0 in range(n - m + 1):
            if match(y0, x0):
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    main()

Solution (Python):
n, m = [int(i) for i in input().split()]
a = ["" for _ in range(n)]
b = ["" 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):
    for j in range(n - m + 1):
        
        match = True
        for k in range(m):
            
            
            
            
            if b[k] != a[i+k][j:j+m]:
                match = False
                break
        if match:
            print("Yes")
            exit()
print("No")

Solution (Python):
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for j in range(m)]
res = 'No'
for k in range(n-m+1):
    for l in range(n-m+1):
        if list(map(lambda o:o[l:l+m],a[k:k+m]))==b:
                    res = 'Yes'
print(res)

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

for s in range(n - m + 1):
    for t in range(n - m + 1):
        for i in range(s, m + s):
            for j in range(t, m + t):
                if a[i][j] != b[i - s][j - t]:
                    break
            else:  
                if i == m + s - 1 and j == m + t - 1:
                    print("Yes")
                    exit()
                continue  
            break  
print("No")

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

a=[]
b=[]

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

N=0

for i in range(M):
    b.append(input())
    if(b[i] in a[i]):
        N+=1

if(N==M):
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
N, M = map(int, raw_input().split())
A = [raw_input() for i in range(N)]
B = [raw_input() for i in range(M)]
for i in range(N):
    if i + M - 1 >= N:
        break
    for j in range(N):
        if j + M - 1 >= N:
            break
        match = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    match = False
                    break
            if not match:
                break
        if match:
            print "Yes"
            sys.exit(0)
print "No"

Solution (Python):
import sys
N, M = map(int, raw_input().split())
A = [raw_input() for i in range(N)]
B = [raw_input() for i in range(M)]
for i in range(N):
    if i + M - 1 >= N:
        break
    for j in range(N):
        if j + M - 1 >= N:
            break
        match = True
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    match = False
                    break
            if not match:
                break
        if match:
            print "Yes"
            sys.exit(0)
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):
  for j in range(n):
    k=j+m
    if k <= n:
      if A[i][j:k]== B[0]:
        o=1
        for l in range(i+1,i+m):
          if l<n:
            if A[l][j:k]!=B[o]:
              break
            else:
              o+=1
        if o==m:
          print('Yes')
          exit()
print('No')

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

for i, j in itertools.product(range(N-M+1), repeat=2):
    if [_[j:j+M] for _ in A[i:i+M]] == 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)]
mon = ([row[j:j+m] for row in a[i:i+m]]
      for i in range(n-m+1) for j in range(n-m+1))
print('Yes' if any(c == b for c in mon) 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)]

all_segment = []
for width in range(N - M + 1):
    for height in range(N - M + 1):
        segment = [width_list[width: width + M] for width_list in A_list[height: height + M]]
        all_segment.append(segment)

if B_list in all_segment:
    print('Yes')
else:
    print('No')

Solution (Python):
m,n = [int(x) for x in input().split()]
a = []
b = []
for _ in range(m):
  a.append(input())
m = 0
for i in range(n):
  b.append(input())
  if b[i] in a[i]:
    m += 1
print('Yes') if m == n 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())
for i in range(n-m+1):
    for j in range(n-m+1):
        if [k[j:m + j] for k in a[i:m + i]] == b:
            print("Yes")
            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)]
f=True
for i in range(n-m+1):
  for j in range(n-m+1):
    f=True
    for k in range(i,i+m):
      for l in range(j,j+m):
        if b[k-i][l-j]!=a[k][l]:
          f=False
    if f:
      print('Yes')
      break
  if f:
    break
if not f:
  print('No')

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

isFind = False
for i in range(N-M+1):
    for j in range(N-M+1):

        isFind2 = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    isFind2 = False
                    break
                if(not isFind2):
                    break
        
        if(isFind2):
            isFind = True
            break
    if(isFind):
        break

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

Solution (Python):

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

def match(x, y):
    return all(a[x:x+M]==b for a,b in zip(A[y:], B))

print(any(match(x, y) for y in range(N-M+1) for x in range(N-M+1)) and "Yes" or "No")

Solution (Python):

def match(ofs_x, ofs_y, li_A, li_B):
    for a, b in zip(li_A[ofs_y:], li_B):
        if a[ofs_x:ofs_x + M] != b:
            return False
    return True

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

for y in range(N-M+1):
    for x in range(N-M+1):
        if match(x, y, li_A, li_B):
            print("Yes")
            exit()
print("No")

Solution (Python):



def solve():
    n, m = map(int, input().split())
    img = [input() for _ in range(n)]
    tmp = [input() for _ in range(m)]

    for loop in range(n-m+1):
        for row in range(n-m+1):
            match = True
            for col in range(m):
                if img[col+loop][row:row+m] != tmp[col]:
                    match = False
            if match:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()

Solution (Python):



def solve():
    n, m = map(int, input().split())
    img = []
    tmp = []

    for _ in range(n):
        img.append(input())

    for _ in range(m):
        tmp.append(input())

    loops = n - m + 1
    for loop in range(loops):
        for row in range(loops):
            match = True
            for col in range(m):
                if img[col+loop][row:row+m] != tmp[col]:
                    match = False
            if match:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()

Solution (Python):



def solve():
    n, m = map(int, input().split())
    img = []
    tmp = []

    for _ in range(n):
        img.append(list(map(str, input().split())))

    for _ in range(m):
        tmp.append(list(map(str, input().split())))

    loops = n - m + 1
    for loop in range(loops):
        for row in range(loops):
            match = True
            for col in range(m):
                if img[col+loop][0][row:row+m] != tmp[col][0]:
                    match = False
            if match:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()

Solution (Python):



def solve():
    n, m = map(int, input().split())
    img = []
    tmp = []

    for _ in range(n):
        img.append(list(map(str, input().split())))

    for _ in range(m):
        tmp.append(list(map(str, input().split())))

    
    if n < m:
        print('No')

    loops = n - m + 1
    for loop in range(loops):
        for row in range(loops):
            match = True
            for col in range(m):
                
                
                if img[col+loop][0][row:row+m] != tmp[col][0]:
                    match = False
            if match:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()

Solution (Python):




"""
https://beta.atcoder.jp/contests/abc054/tasks/abc54_1
"""

import sys
import math
from inspect import currentframe

def debug_print(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=sys.stderr)

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


delta = N - M
match = False

if delta == 0:
    match = (A==B)
else:
    for dx in range(delta):
        for dy in range(delta):
            window = [pixels[dx:dx+M] for pixels in A[dy:dy+M]]
            if window == B:
                match = True
                break

if match:
    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)]

for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j] == b[0][0]:
            flag = 0
            for u in range(m):
                for v in range(m):
                    if a[i+u][j+v] != b[u][v]:
                        flag = -1
                        break
                if flag == -1:
                    break
            if flag == 0:
                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)]
i = 0
while(i <= N - M):
    x = A[i].find(B[0])
    while(N - M >= x and x >= 0):
        for j in range(1,M):
            if A[i+j][x:x+M] != B[j]:
                x = A[i].find(B[0], x+1)
                break
        else:
            print("Yes")
            exit()
    i += 1
print("No")

Solution (Python):
tn = []
tm = []

def check(d):
    for h in range(d + 1):
        for w in range(d + 1):
            mw = len(tm)
            result = True
            for tmh in range(mw):
                row = tn[h + tmh][w:w + mw]
                if row != tm[tmh]:
                    result = False
                    break

            if result:
                return True

    return False

N, M = list(map(int, input().rstrip().split()))
for i in range(N):
    tn.append(list(input().rstrip()))

for i in range(M):
    tm.append(list(input().rstrip()))

d = N - M

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

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

def check(i, j):
    
    ret = True
    for h in range(M):
        for w in range(M):
            if A[h+i][w+j] != B[h][w]:
                ret = False

    return ret
                
    
for i in range(N-M+1):
    for j in range(N-M+1):
        if check(i, j):
            print("Yes")
            sys.exit()
else:
    print("No")

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None

def is_match(A, B, sy, sx):
    for y in range(len(B)):
        for x in range(len(B)):
            if A[y+sy][x+sx] != B[y][x]:
                return False
    
    return True

def main():
    N, M = li_input()
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]

    for sy in range(N - M + 1):
        for sx in range(N - M + 1):
            if is_match(A, B, sy, sx):
                print("Yes")
                return
    
    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)]
dxy = []
for y in range(M) :
    for x in range(M) :
        dxy.append((x,y))
flag = 0
for y in range(N) :
    for x in range(N) :
        if A[y][x] == B[0][0] and flag == 0 :
            counter = 0
            for dx,dy in dxy :
                if flag == 0 :
                    nx = x+dx
                    ny = y+dy
                    if not (0 <= nx <= N-1) :
                        break
                    if not (0 <= ny <= N-1) :
                        break
                    if A[ny][nx] == B[dy][dx] :
                        counter += 1
            if counter == M**2 :
                flag = 1
if flag == 1 :
    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)]

dxy = []
for y in range(M) :
    for x in range(M) :
        dxy.append((x,y))
flag = 0
for y in range(N) :
    for x in range(N) :
        if A[y][x] == B[0][0] and flag == 0 :
            counter = 0
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= N-1) and (0 <= ny <= N-1) and flag == 0 :
                    if A[ny][nx] == B[dy][dx] :
                        counter += 1
                if counter == M**2 :
                    flag = 1
if flag == 1 :
    print("Yes")
else :
    print("No")

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

    a = [input() for _ in range(n)]
    b = [input() for _ in range(m)]

    for i in range(n - m + 1):
        j = a[i].find(b[0])
        while j != -1:
            if judge(a, b, m, i, j):
                print('Yes')
                return
            j = a[i].find(b[0], j + 1)
    print('No')

def judge(a, b, m, i, j):
    for k in range(m):
        if a[i + k][j:j+m] != b[k]:
            return False
    return True

main()

Solution (Python):

import sys
from numpy import array as npa

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

for i in range(n-m+1):
    for j in range(n-m+1):
        if ((b[:, :] == a[i:i+m, j:j+m]).all()):
            print('Yes')
            sys.exit(0)

print('No')

Solution (Python):

import sys
import numpy as np

n,m = (int(_) for _ in input().split())
a = np.array([list(input()) for i in range(n)])
b = np.array([list(input()) for i in range(m)])

for i in range(n-m+1):
    for j in range(n-m+1):
        if ((b[:, :] == a[i:i+m, j:j+m]).all()):
            print('Yes')
            sys.exit(0)

print('No')

Solution (Python):

import sys

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





for i in range(n-m+1):
    for j in range(n-m+1):
        if (b[::1] == [ai[j:j+m] for ai in a[i:i+m]]):
            print('Yes')
            sys.exit(0)

print('No')

Solution (Python):

import sys

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

if(a[::1] == b[::1]):
    print('Yes')
    sys.exit(0)

for i in range(n-m):
    for j in range(n-m):
        if (b[::1] == [ai[j:j+m] for ai in a[i:i+m]]):
            print('Yes')
            sys.exit(0)

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 [k[j:m+j] for k in a[i:m+i]] == 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)]

cs = ([row[j:j+m] for row in a[i:i+m]]
      for i in range(n-m+1) for j in range(n-m+1))
print('Yes' if any(c == b for c in cs) else 'No')

Solution (Python):
from sys import stdin
il = lambda func=int: list(map(func, stdin.readline().rstrip().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n, m = il()
a = ils(n, "input()")
b = ils(m, "input()")
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = 1
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    flag = 0
        if flag:
            print("Yes")
            exit()
print("No")

Solution (Python):
from sys import stdin


def main() -> None:
    global N, M, A, B
    N = next_int()
    M = next_int()
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]

    ans = "No"
    for Ni in range(N):
        for Nj in range(N):
            if judge(Ni, Nj):
                ans = "Yes"
                break
        if ans == "Yes":
            break
    print(ans)


def judge(ni: int, nj: int) -> bool:
    for i in range(M):
        for j in range(M):
            if ni + i >= N or nj + j >= N:
                return False
            if B[i][j] != A[ni + i][nj + j]:
                return False
    return True


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
from sys import stdin


def main() -> None:
    global N, M, A, B
    N = next_int()
    M = next_int()
    A = np.array([input() for _ in range(N)])
    B = np.array([input() for _ in range(M)])

    ans = "No"
    for Ni in range(N):
        for Nj in range(N):
            if judge(Ni, Nj):
                ans = "Yes"
                break
        if ans == "Yes":
            break
    print(ans)


def judge(ni: int, nj: int) -> bool:
    for i in range(M):
        for j in range(M):
            if ni + i >= N or nj + j >= N:
                return False
            if B[i][j] != A[ni + i][nj + j]:
                return False
    return True


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

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 A[i+k][j+l] != B[k][l]:
                    flag = 1
                    break
        if flag == 0:
            print("Yes")
            break
    if flag == 0:
        break
        
if flag == 1:
    print("No")

Solution (Python):
N, M = map( int, input().split())
A = ['']*N
B = ['']*M
for i in range(N):
    a = input()
    A[i] = a
for i in range(M):
    b = input()
    B[i] = b
k=N-M+1
ans = 'No'
for i in range(k):
    for j in range(k):
        now = 1
        for l in range(M):
            if not A[i+l][j:j+M] == B[l]:
                now = -1
                break
        if now == 1:
            ans = 'Yes'
            break
    if ans == 'Yes':
        break
print(ans)

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


for x in range(N-M+1):
    for y in range(N-M+1):
        for j in range(M):
            
            
            if A[y+j][x:x+M] != B[j]:
               
                break
        else:
            ans ='Yes'
            

print(ans)

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

a = []
b = []

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

k = 0 
c = 0
d = 0

for i in range(n-m+1):
    for j in range(n-m+1):
        v = 0
        for w in range(m):
            for r in range(m):
                if b[w][r] == a[i+w][j+r]:
                    v += 1
        if v == m**2:
            k = 1

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

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

for _ in range(n):
    a += [list(input())]

for _ in range(m):
    b += [list(input())]

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

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

for _ in range(n):
    a += [list(input())]
for _ in range(m):
    b += [list(input())]

for i in range(n-m+1):
    for j in range(n-m+1):
        if [k[j:m+j] for k 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)]

Match = False
for i in range(N-M+1):
    for j in range(N-M+1):
        Compare = [A[k][j:j+M] for k in range(i, i+M)]
        if Compare == B:
            Match = True
print("Yes" if Match else "No")

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

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

Solution (Python):
N, M = map(int, input().split())
T = [[""] for i in range(N)]
S = [[""] for i in range(M)]
for i in range(N):
    a = input()
    T[i] = a

for i in range(M):
    b = input()
    S[i] = b

flag = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if T[i][j] == S[0][0]:
            flag1 = True
            for k in range(M):
                for l in range(M):
                    if T[i + k][j + l] != S[k][l]:
                        flag1 = False
            if flag1:
                flag = True

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

Solution (Python):
n, m = (int(i) for i in input().split())

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

for i in range(m):
    b.append(input())
     
for i in range(n - m + 1):
    if b[0] in a[i]:
        pos = a[i].find(b[0])
        flag = 0
        for j in range(m):
            if a[i+j][pos:pos+m] == b[j]:
                pass
            else:
                flag = -1
                break
        if flag == 0:
            print("Yes")
            exit(0)
     
print("No")

Solution (Python):
n,m = map(int, input().split())
list_a = []
list_b = []
count = 0
while count < n:
    list_a.append(list(str(input())))
    count += 1
count = 0
while count < m:
    list_b.append(list(str(input())))
    count += 1


phase = 0
if list_a != list_b:
    for i in range(0, n-m):
        for j in range(0, n-m):
            for k in range(0,m):
                if list_a[i+k][j:j+m] == list_b[k]:
                    if k != m-1:
                        continue
                    else:
                        pass
                else:
                    break
                phase = 1
                print("Yes")
                break
            if phase == 1:
                break
        if phase == 1:
            break
    else:
        print("No")
else:
    print("Yes")

Solution (Python):
n,m=map(int,input().split())
a=[]
b=[]
c=n-m+1
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
ans='No'
for i in range(c):
    for j in range(c):
        flag=0
        for k in range(m):
            if b[k]==a[i+k][j:j+m]:
                flag+=1
        if flag==m:
            ans='Yes'
            break
print(ans)