Problem:


Score : 200 points

Problem Statement

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

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

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

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

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

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

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

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

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

Constraints

1≦M≦N≦50 

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

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

Input

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

N M
A_1
A_2
:  
A_N
B_1
B_2
:  
B_M

Output

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

Sample Input 1

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

Sample Output 1

Yes

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

Sample Input 2

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

Sample Output 2

No

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



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


Sample output:
Yes

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Als = []
Bls = []
ans = 'No'
if Bls == Als:
    ans = 'Yes'
for i in range(N):
    Als.append(input())
for i in range(M):
    Bls.append(input())
for i in range(N-M):
    for j in range(0,N-M):
        for k in range(M):
            if Bls[k] == Als[i+k][j:M+j]:
                ans = 'Yes'
            else:
                ans = 'No'
                break
        if ans == 'Yes':
            break
    if ans == 'Yes':
        break
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(input()) for _ in range(n)]
b=[list(input()) for _ in range(m)]
r=n-m+1
print('Yes' if any([all([a[x//r+y//m][x%r+y%m]==b[y//m][y%m] for y in range(m**2)]) for x in range(r**2)]) else 'No')

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[list(input()) for _ in range(n)]
b=[list(input()) for _ in range(m)]
r=n-m+1
for x in range(r**2):
  for y in range(m**2):
    if a[x//r+y//m][x%r+y%m]!=b[y//m][y%m]:
      break
  else:
    print('Yes')
    break
else:
  print('No')

Submission status: Accepted

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

eq = False
find = False
for i in range(n-m+1):
  for j in range(n-m+1):
    for p in range(m):
      for q in range(m):
        if a[p+i][q+j] == b[p][q]:
          eq = True
        else:
          eq = False
          break
      if not eq:
        break
    if eq:
      find = True
      break
  if find:
    break
if find:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = ["" for _ in range(n)]
b = ["" for _ in range(m)]
for i in range(n):
    a[i] = str(input())
for i in range(m):
    b[i] = str(input())
def check(ini_x, ini_y):
    global n, m, a, b
    for x in range(m):
        for y in range(m):
            if a[ini_x + x][ini_y + y] != b[x][y]:
                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()
print("No")

Submission status: Accepted

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

for i in range(K):
  for j in range(K):
    # print(i,i+M,j,j+M)
    if all(all(A[k+i][l+j] == B[k][l] for l in range(M)) for k in range(M)):
      print('Yes')
      exit()
else:
  print('No')

Submission status: Accepted

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

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 an[i+k][j+l] != bm[k][l] :
            match = False
            break
          else :
            continue
      if match :
        print("Yes")
        exit()
                    
print("No")

Submission status: Accepted

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

a_list = []
b_list = []
ans = "No"

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

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

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_list[i+k][l+j] != b_list[k][l]:
                    match = False
        if match:
            ans = "Yes"
            break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
b = []
for i in range(n):
    a.append(str(input()))
for j in range(m):
    b.append(str(input()))
#print(a)
#print(b)
isOK = False
#print(a[0][0:m])
#print(b[0])
#print(a[0][1:m+1])
#print(b[0])
#print(a[1][0:m])
#print(b[1])
#print(a[1][1:m+1])
#print(b[1])

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = []
c = []
for i in range(N):
    b = list(input())
    a+=b
for i in range(M):
  b = list(input())
  c+=b
#print(c,a)
f = False
for i in range(N*N):
  if f == True:
    break
  if N*N-i<M*M:
    break
  if M>1 and i//N==N-1:
    break
  count=0
  flag = True
  #print(i,c[0],a[i])
  if c[0] == a[i]:
    if N-((i)%N)<M:
      continue
    num = i
    for j in range(M):
      for k in range(M):
        #print(c[count],a[num])
        if c[count] == a[num]:
          
          num+=1
          count+=1
        elif c[count]!=a[num]:
          flag =False
          break
      num+=N-M
      if flag == False:
        #print(i)
        break  
      if j == M-1:
        f = True
            
  else:
    continue
if f == False:
  print('No')
else:
  print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

n, m = [int(i) for i in input().split()]

img_a = []
img_b = []

for i in range(n):
    img_a.append(list(input().strip()))

for i in range(m):
    img_b.append(list(input().strip()))


if img_a == img_b:
    print("Yes")
    sys.exit()

for i in range(0, n - m + 1):
    for j in range(0, n - m + 1):
        grid = [line[j:j + m] for line in img_a[i:i + m]]
        if grid == img_b:
            print("Yes")
            sys.exit()

print("No")

Submission status: Accepted

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

def c(a, m, x, y):
  tmp = []
  for i in range(m):
    tmp.append(a[y+i][x:x+m])
  return tmp

for x in range(n - m + 1):
  for y in range(n - m + 1):
    if c(a, m, x, y) == b:
      print("Yes")
      exit(0)
print("No")

Submission status: Accepted

Solution code:
def resolve():
    N, M = map(int, input().split())
    A = []
    B = []
    ans = 0
    for _ in range(N):
        a = input()
        A.append(a)
    for __ in range(M):
        b = input()
        B.append(b)
    for i in range(N-M+1):
        for j in range(N-M+1):
            flag = 0
            for p in range(M):
                for q in range(M):
                    if A[i+p][j+q] != B[p][q]:
                        flag = 1
            if flag == 0:
                ans = 1
    print("Yes" if ans == 1 else "No")
resolve()

Submission status: Accepted

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

ans="No"
for j in range(N-M+1):
    for i in range(N-M+1):
        isMatch=True
        for y in range(M):
            for x in range(M):
                if A[j+y][i+x]!=B[y][x]:
                    isMatch=False
                    
        if isMatch:
            ans="Yes"
            break        

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

A=[list(map(int,list(input().replace('.','0').replace('#','1')))) for _ in range(N)]
B=[list(map(int,list(input().replace('.','0').replace('#','1')))) for _ in range(M)]

A,B=map(np.array,(A,B))

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

print('No')

Submission status: Accepted

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

b_str = ''.join(B_list)
def judge_same(str1, str2):
    return str1 == str2
judge = False
finish = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        a_str = ''.join([A_list[i + x][j:(j+M)] for x in range(M)])
        judge = judge_same(a_str, b_str)
        if judge:
            finish = True
            break
    if finish:
        break
if judge:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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


N, M = list(map(lambda x: int(x), input().split(" ")))
A = []
B = []
for i in range(N):
  A.append(list(input()))
for j in range(M):
  B.append(list(input()))

has = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    if A[i][j] == B[0][0]:
      has = hasB(A, B, M, j, i)
      if has:
        break
  else:
    continue
  
  break

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = [str(input()) for i in range(n)]
b = [str(input()) for i in range(m)]
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        ans = 1
        for k in range(0,m):
            for l in range(0,m):
                if a[i+k][j+l] != b[k][l]:
                    ans = 0
                    break
        if ans == 1:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

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

for s in range(N-M+1):
    for t in range(N-M+1):
        match = True
        for i in range(M):
            for j in range(M):
                if A[i+s][j+t] != B[i][j]:
                    match = False
                    break
            else:
                continue
            break
        if match:
            print('Yes')
            exit()
print('No')

Submission status: Accepted

Solution code:
def solve():
    def check(i, j, m):
        for h in range(m):
            for w in range(m):
                if A[h+i][w+j] != B[h][w]:
                    return False
        return True
    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 check(i, j, M):
                print("Yes")
                return
    print("No")
    return

solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = [list(input())[: -1] for _ in range(N)]
b = [list(input())[: -1] for _ in range(M)]
for i in range(N - M + 1):
  for j in range(N - M + 1):
    for y in range(M):
      for x in range(M):
        if a[i + y][j + x] != b[y][x]: break
      else: continue
      break
    else:
      print("Yes")
      exit(0)
print("No")

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]

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


#n = ["abc","cde","xzy"]
#m = ["abc","cde","jzy"]
a = []
b = []
n,m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

temp = n - m + 1


for i in range(temp):
    for j in range(temp):
        #[i][j]を起点として比較
        for k in range(m):
            for l in range(m):
                if equal(a,b,i,j,m):
                    print("Yes")
                    exit()
print("No")

Submission status: Accepted

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

A, B = np.array(A), np.array(B)

for i in range(n-m+1):
    for j in range(n-m+1):
        tmp = A[i:i+m, j:j+m]
        # 普通にtmp == Bで比較すると要素ごとの一致不一致が返るので,
        # 全体の一致を判定するall()を利用する
        if (tmp == B).all():
            print("Yes")
            exit()
else:
    print("No")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
b1=b[0]
res="No"
for i in range(n-m+1):
    if b1 in a[i]:
        x=a[i].index(b1)
        match=1
        for j in range(1,m):
            if a[i+j][x:x+m]!=b[j]:
                match=0
        if match:
            res="Yes"
print(res)

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    flag = False
    tmp = [a[f][j:j+m] for f in range(i, i+m)]
    for k in range(m):
      for l in range(m):
        if tmp[k][l] != b[k][l]:
          flag = True
          break
      if flag:
        break
    if flag:
      continue
    print("Yes")
    sys.exit()
print("No")

Submission status: Accepted

Solution code:
n, m = [int(s) for s in input().split()]
a_list = [input() for _ in range(n)]
b_list = [input() for _ in range(m)]
stop = n - m + 1
for i in range(stop):
    for j in range(stop):
        break_flag = False
        for x in range(m):
            for y in range(m):
                if a_list[i + x][j + y] != b_list[x][y]:
                    break_flag = True
                    break
            if break_flag:
                break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N-M+1):
    for j in range(N-M+1):
        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")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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")

Submission status: Accepted

Solution code:
#!/usr/bin/env 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')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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)
# print(A)
# print(B)
ans = False
for i in range(1, N - M + 2):
    for j in range(1, N + 2 - M):
        is_exist = True
        # print('=======', i, j)
        for k in range(1, M + 1):
            for l in range(1, M + 1):
                # print(k, l, B[k][l], A[i + k - 1][j + l - 1], A[i - 1][j], A[i][j - 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')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
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')

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = list(input() for _ in range(N))
B = list(input() for _ in range(M))
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)

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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():
	#a = int(input())
	n, m = tin()
	#s = input()
	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
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print('No')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
#print(A,B)
for i in range(N-M+1): #0~N-M
  for j in range(N-M+1): 
    Flag = True
    for p in range(M):
      for q in range(M):
        #print(i+p,j+q,p,q)
        if A[i+p][j+q] != B[p][q]:
          Flag = False
    if Flag:
      print("Yes")
      exit()
print("No")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
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")

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    
    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()

Submission status: Accepted

Solution code:
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")