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: Wrong Answer

Solution code:
# abc54c

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

FLG = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        flg = 0
        for k in range(M):
            if B[k]==A[i+k][j:j+M]:
                flg = 1
        if flg: FLG = 1

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

Submission status: Wrong Answer

Solution code:
# abc54c

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

flg = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            if B[k]==A[i+k][j:j+M]:
                flg = 1

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
    A.append(list(input()))
for j in range(M):
    B.append(list(input()))
import copy
CA = copy.deepcopy(B)
ans = -1
for i in range(N - M + 1):
    for j in range(M):
        for k in range(M):
            CA[j][k] = A[i + j][i + k]
    if CA == B:
        print("Yes")
        ans = 1
        break
if ans == -1:
    print("No")

Submission status: Wrong Answer

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):
    if B[0] in A[i]:
        if all(B[j] in A[i+j] for j in range(1,min(M,N-i))):
            print('Yes')
            exit(0)
print('No')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(1,m):
        if b[r]!=a[p+r][q:q+m]:break
        c=1
if c==0:print('No')
else:print('Yes')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(1,m):
        if b[r]!=a[p+r][q:q+m]:break
        c=1
        break
if c==0:print('No')
else:print('Yes')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(1,m):
        if b[r]!=a[p+r][q:q+m]:break
      c=1
if c==0:print('No')
else:print('Yes')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[list(input()) for a in range(n)]
b=[list(input()) for a in range(m)]
c=0
for p in range(n-m+1):
  for q in range(n-m+1):
    if b[0]==a[p][q:q+m]:
      for r in range(1,m):
         if b[r]!=a[p+r][q:q+m]:break
      c=1
      break
if c==0:print('No')
else:print('Yes')

Submission status: Wrong Answer

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

def match(ofs_x, ofs_y):
    for ar,br in zip(A[ofs_y:], B):
        if ar[ofs_x:] != br:
            return False
    return True

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

Submission status: Wrong Answer

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

def match(ofs_x, ofs_y):
    for ar,br in zip(A[ofs_y:], B):
        if ar[ofs_x:] != br:
            return False
    return True

for y in range(N-M+1):
    for x in range(N-M+1):
        if match(x,y):
            print('YES')
            exit()
print('NO')

Submission status: Wrong Answer

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

aList = []
bList = []
aListSlice = []
answer = 'No'

for i in range(n):
    aList = aList + list(input())

for j in range(m):
    bList = bList + list(input())

for right in range(n-m+1):
    for down in range(n-m+1):
        for k in range(m):
            idx = n*(k+down)+right
            aListSlice = aListSlice + aList[idx:idx+m]
        if bList == aListSlice:
            answer = 'Yes'
            break

print(answer)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python3

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

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

res = False

for r in range(n):
    offset = 0
    while True:
        offset = a[r].find(b[0], offset + 1)

        if offset == -1:
            break

        flg = True
        for r2 in range(1, m):
            if r + r2 >= n:
                flg = False
                break
            if a[r + r2].find(b[r2], offset) != offset:
                flg = False
                break

        if flg == True:
            res = True
            break

    if res == True:
        break
            
if res == True: print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
n,  m = map(int, input().split())
np = [input() for _ in range(n)]
mp = [input() for _ in range(m)]
for i in range(n-m+1):
  for j in range(n-m):
    f = True
    for k in range(m):
      if np[i+k][j:j+m] != mp[k]:
        f = False
    if f:
      print("Yes")
      exit(0)
else:
  print("No")

Submission status: Wrong Answer

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

ans = 0

for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            for l in range(M):
                if B[k][l] == A[i + k][j + l]:
                    ans += 1
                else:
                    break
        if ans == M * 2:
            print("Yes")
            exit()
        else:
            ans = 0

print('No')

Submission status: Wrong Answer

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

img = [input() for i in range(n)]
template = [input() for i in range(m)]

for i in range(n - m + 1):
    st = {v.find(t) for v, t in zip(img[i:i + m], template)}
    if len(st) == 1 and -1 not in st:
        print("Yes")
        break
else:
    print("No")

Submission status: Wrong Answer

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

# データ構造の設定が上手と思った
# 配列の配列にせず、文字列の配列にしている点
A = [input() for j in range(N)]
B = [input() for j in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            if A[i+k][j:j+k] != B[k]:
                break
        else:
            print("Yes")
            exit()
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from itertools import product
N, M = list(map(int, input().split()))
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]
flag = False

for _i, _j in product(range(N - M + 1), range(N - M + 1)):
    if A[_i][_j] == B[0][0] and [_A[_j:_i+M] for _A in A[_i:_i+M]] == B:
        flag = True
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from itertools import product
N, M = list(map(int, input().split()))
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = False

for _i, _j in product(range(N - M + 1), range(N - M + 1)):
    if [_A[_j:_i+M] for _A in A[_i:_i+M]] == B:
        flag = True
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from itertools import product
N, M = list(map(int, input().split()))
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = False

for _i, _j in product(range(N - M + 1), range(N - M + 1)):
    if A[_i][_j] == B[0][0] and [_A[_j:_i+M] for _A in A[_i:_i+M]] == B:
        flag = True
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

for _i in range(N - M + 1):
    for _j in range(N - M + 1):
        if A[_i][_j] == B[0][0]:
            if [_A[_j:_i+M] for _A in A[_i:_i+M]] == B:
                print('Yes')
                flag = True
                break
    if flag:
        break
if not flag:
    print('No')

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())

A = []*N
for i in range(N):
    a = input()
    tmp = []
    for j in range(N):
        tmp.append(a[j])
    A.append(tmp)

B = []*M
for i in range(M):
    b = input()
    tmp = []
    for j in range(M):
        tmp.append(b[j])
    B.append(tmp)
    

same = False
for i in range(N-M+1):
    count = 0
    for j in range(M):
        for k in range(M):
            if B[j][k] == A[j+i][k+i]:
                count += 1
    if count >= M*M:
        same = True
        break



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

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())

A = []*N
for i in range(N):
    a = input()
    tmp = []
    for j in range(N):
        tmp.append(a[j])
    A.append(tmp)

B = []*M
for i in range(M):
    b = input()
    tmp = []
    for j in range(M):
        tmp.append(b[j])
    B.append(tmp)
    

same = False
for i in range(N-M+1):
    count = 0
    for j in range(M):
        for k in range(M):
            if B[j][k] == A[j+i][k+i]:
                count += 1
    if count == M*M:
        same = True
        #break



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

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())

A = []*N
for i in range(N):
    a = input()
    tmp = []
    for j in range(N):
        tmp.append(a[j])
    A.append(tmp)

B = []*M
for i in range(M):
    b = input()
    tmp = []
    for j in range(M):
        tmp.append(b[j])
    B.append(tmp)
    

same = False
for i in range(N-M+1):
    count = 0
    for j in range(M):
        for k in range(M):
            if B[j][k] == A[j+i][k+i]:
                count += 1
    if count == M*M:
        same = True
        break



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

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())

A = []*N
for i in range(N):
    a = input()
    tmp = []
    for j in range(N):
        tmp.append(a[j])
    A.append(tmp)

B = []*M
for i in range(M):
    b = input()
    tmp = []
    for j in range(M):
        tmp.append(b[j])
    B.append(tmp)
    

same = False
for i in range(N-M+1):
    count = 0
    for j in range(M):
        for k in range(M):
            if B[j][k] == A[j+i][k+i]:
                count += 1
    if count == M*M:
        same = True
        break

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

Submission status: Wrong Answer

Solution code:
N,M = (int(i) for i in input().split())

A = []*N
for i in range(N):
    a = input()
    tmp = []
    for j in range(N):
        tmp.append(a[j])
    A.append(tmp)

B = []*M
for i in range(M):
    b = input()
    tmp = []
    for j in range(M):
        tmp.append(b[j])
    B.append(tmp)
    

same = False
for i in range(N-M):
    count = 0
    for j in range(M):
        for k in range(M):
            if B[j][k] == A[j+i][k+i]:
                count += 1
    if count == M*M:
        same = True
        break

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

Submission status: Wrong Answer

Solution code:
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 h in range(N-M):
    for w in range(N-M):
        if list(map(lambda x:x[w:w+M], A[h:h+M])) == B:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M=[int(i) for i in input().split()]
A=[]
for i in range(N):
    a=[i for i in input()]
    A.append(a)
B=[]
for i in range(M):
    b=[i for i in input()]
    B.append(b)    
flag=False
for i in range(N-M+1):
    for j in range(N-M+1):
        s=0
        if B[0][0]==A[i][j]:    
            for k in range(M):
                for l in range(M):
                    if B[0+k][0+l]==A[i+k][j+l]:
                        s+=1
            if s==M**2:
                flag=True
        else:
            break            
if flag==True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n, m = [int(i) for i in input().split()]
a = []
for i in range(n):
    tmp = input()
    a.append(tmp)
b = []
for i in range(m):
    tmp = input()
    b.append(tmp)
f = False
for i in range(n - m):
    for j in range(n - m):
        g = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    g = False
        if g:
            f = True
if f:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n-m+1):
    for j in range(m):
        for k in range(n):
            match = False
            if a[i][k: k+m] == b[j] and not exits:
                for l in range(1, m):
                    if a[i+l][k: k+m] == b[l]:
                        match = True
                    else:
                        match = False
                        break
            if match:
                exits = True

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

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(m):
        for k in range(n):
            match = False
            if a[i][k: k+m] == b[j] and not exits:
                for l in range(1, m):
                    if a[l][k: k+m] == b[l]:
                        match = True
                    else:
                        match = False
                        break
            if match:
                exits = True

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

Submission status: Wrong Answer

Solution code:
import sys
import os

def is_same(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            return False
    return True

N, M = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

A = []
B = []

for _ in range(N):
    A.append(sys.stdin.readline().strip())

for _ in range(M):
    B.append(sys.stdin.readline().strip())

it = N - M + 1

for i in range(it):
    for j in range(it):
        a = list(map(lambda x: x[j:i+M], A[i:i+M]))
        if is_same(a, B):
            print("Yes")
            sys.exit(0)
print("No")

Submission status: Wrong Answer

Solution code:
import sys
import os

def is_same(a, b):
    for i in range(len(a)):
        if a[i] != b[i]:
            return False
    return True

N, M = list(map(lambda x: int(x), sys.stdin.readline().strip().split(" ")))

A = []
B = []

for _ in range(N):
    A.append(sys.stdin.readline().strip())

for _ in range(M):
    B.append(sys.stdin.readline().strip())

it = N - M + 1

for i in range(it):
    for j in range(it):
        if is_same(A[i:i+M][j:j+M], B):
            print("Yes")
            sys.exit(0)
print("No")

Submission status: Wrong Answer

Solution code:
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
for i in range(n-m+1):
    for j in range(n-m+1):
        judge=False
        if a[i][j]==b[0][0]:
            if match(i,j):
                judge=True
                break
print("Yes"if judge else "No")

Submission status: Wrong Answer

Solution code:
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
for i in range(n-m+1):
    for j in range(n-m+1):
        judge=False
        if a[i][j]==b[0][0]:
            if match(i,j):
                judge=True
print("Yes"if judge else "No")

Submission status: Wrong Answer

Solution code:
import numpy as np

N, M = map(int, input().split())
n_img = []
m_img = []

for _ in range(N):
    n_img.append([0 if e == '#' else 1 for e in list(input())])
for _ in range(M):
    m_img.append([0 if e == '#' else 1 for e in list(input())])

n_img = np.array(n_img)
m_img = np.array(m_img)


def areSameM(m1, m2):
    s = np.sum(np.sum(abs(m1 - m2)))
    return s == 0


flag = False

for i in range(N - M):
    for j in range(N - M):
        if areSameM(n_img[i:i + M, j:j + M], m_img):
            flag = True
            break
    if flag:
        break

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

Submission status: Wrong Answer

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

A,B = [],[]
for i in range(N): A.append(input())
for j in range(M): B.append(input())
    
isok = False
for h in range(0,N-M):
    for w in range(0,N-M):
        #始点を合わせたら照合開始
        search = True #照合を仮定(ダメなら-1に変更)
        for j in range(M):
            if A[h+j][w:w+M] != B[j]:
                search = False
                break
        if search:
            isok = True
            break
        #照合ここまで
    if search:break
        
if isok:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split(' '))
i_A = [list(input()) for _ in range(N)]
i_B = [list(input()) for _ in range(M)]
flag = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        if i_B[0] == i_A[i][j:j+M]:
            flag = 1
            for k in range(1, M):
                if not i_B[k] == i_A[i+k][j:j+M]:
                    flag = 0
        else: flag = 0
if flag == 1: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(M):
    for j in range(N-M):
        str_n = ''.join(A[i][j:j+M])
        if str_n == B[i]:
            break
    else:
        print("No")
        exit()
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
A = []
for i in range(N):
    A.append(input())
B = []
for i in range(M):
    B.append(input())
ans = False
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            if all([A[i+h][j:j+M+1] == B[h] for h in range(M)]):
                ans = True
print("Yes") if ans else print("No")

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
flag=0
for i in range(N-M):
  for j in range(N-M):
    flag2=1
    for x in range(M):
      for y in range(M):
        if A[i+x][j+y]!=B[x][y]:
          flag2=0
          break
      if flag2==0:
        break
    if flag2==1:
      flag=1
      break
  if flag==1:
    break
if flag==1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
f = False
for i in range(n - m):
    for j in range(n - m):
        ok = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    ok = False
                    break
            if not ok: break
        if ok:
            f = True
            break
    if f: break
if f: print('Yes')
else: print('No')

Submission status: Wrong Answer

Solution code:
def contains(a, b, n, m):
    def eq(i, j):
        for row in range(m):
            if b[row] != a[i + row][j:]:
                return False
        return True

    if m <= n:
        for i in range(n - m + 1):
            for j in range(n - m + 1):
                if eq(i, j):
                    return True
    return False


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    a = [list(input()) for _ in range(n)]
    b = [list(input()) for _ in range(m)]
    print('Yes') if contains(a, b, n, m) else print('No')

Submission status: Wrong Answer

Solution code:
def contains(a, b, n, m):
    def eq(i, j):
        for row in range(m):
            if b[row] != a[i + row][j:]:
                return False
        return True

    if m < n:
        for i in range(n - m + 1):
            for j in range(n - m + 1):
                if eq(i, j):
                    return True
    return False


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    a = [list(input()) for _ in range(n)]
    b = [list(input()) for _ in range(m)]
    print('Yes') if contains(a, b, n, m) else print('No')

Submission status: Wrong Answer

Solution code:
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):
  for j in range(n-m):
    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')

Submission status: Wrong Answer

Solution code:
import sys
n, m = map(int, input().split())
n_list = [list(input()) for i in range(n)]
m_list = [list(input()) for i in range(m)]

def bunkatu(x, y):
    global n_list
    lis = []
    for i in range(y, y + m):
        lis.append(n_list[i][x: x + m])
    return lis

for j in range(n - m + 1):
    for i in range(n - m + 1):
        tmp = bunkatu(i, j)
        if m_list == tmp:
            print('YES')
            sys.exit(0)
print('NO')

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int,input().split())
Ai=[]
Bi=[]
for i in range(N):
    Ai.append(input())
for i in range(M):
    Bi.append(input())
roop=N-M
for i in range(roop):
    for j in range(roop):
        #print("A")
        flag=1
        for k in range(M):
            #print(Ai[i+k][j:j+M])
            if(Ai[i+k][j:j+M]!=Bi[k]):
                flag=0
                break;
        if(flag==1):
            print("Yes")
            sys.exit()
print("No")

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int,input().split())
Ai=[]
Bi=[]
for i in range(N):
    Ai.append(input())
for i in range(M):
    Bi.append(input())
roop=N-M+1
for i in range(roop):
    for j in range(roop):
        flag=1
        for k in range(roop):
            if(Ai[i+k][j:j+roop]!=Bi[k]):
                flag=0
                break;
        if(flag==1):
            print("Yes")
            sys.exit()
print("No")

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
A = [input().strip() for _ in range(N)]
B = [input().strip() for _ in range(M)]
flag = 0
for v in range(N-M):
  for h in range(N-M):
    for i in range(M):
      for j in range(M):
        if A[v+i][h+j] == B[i][j]:
          flag += 1
    if flag == M*M:
      break
    else:
      flag = 0
  if flag == M*M:
    break

if flag==0:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
A = [input().strip() for _ in range(N)]
B = [input().strip() for _ in range(M)]
ans = 'Yes'
for v in range(N-M):
  for h in range(N-M):
    for i in range(M):
      for j in range(M):
        if A[v+i][h+j] != B[i][j]:
          ans = 'No'
print(ans)

Submission status: Wrong Answer

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

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




flag=0
for i in range(N-M):
    for j in range(N-M):
        for t in range(M):
            for s in range(M):
                if A[i+t][j+s]==B[t][s]:
                    flag+=1
        if flag==M*M: break
        else: flag=0

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

Submission status: Wrong Answer

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

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




flag=0
for i in range(N-M+1):
    for j in range(N-M+1):
        for t in range(M):
            for s in range(M):
                if A[i+t][j+s]==B[t][s]:
                    flag+=1
        if flag==M*M: break
        else: flag=0

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

Submission status: Wrong Answer

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

A=[]
for i in range(N):
    a=list(input())
    A.append(a)

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

An=np.array(A)
Bn=np.array(B)

t=0
for i in range(N-M):
    for j in range(N-M):
        if Bn in An[i:i+M,j:j+M]:
            t=1
            break

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

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
def na():
    return map(int,stdin.readline().split())
def ns():
    return stdin.readline().strip()
N, M = na()
a = []
b = []

for i in range(N):
    a.append(ns())
for i in range(M):
    b.append(ns())

for i in range(N-M+1):
    for j in range(N-M+1):
        flag = True
        for k in range(M):
            if a[i+k][j:j+M] != b[k]:
                flag = False
                break

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

Submission status: Wrong Answer

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

for i in range(N):
    for j in range(M):
        for k in range(M):
            if B[j][k] in A[i]:
                p += 1


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

Submission status: Wrong Answer

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

for i in range(N):
    for j in range(M):
        for k in range(M):
            if B[j][k] in A[i]:
                continue
            else:
                p = -1

if p == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
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(len(a[0]) - len(b[0]) + 1):
        for k in range(m):
            if a[i+k][j:(j+m+1)] != b[k]:
                break
            print('Yes')
            quit()
print('No')

Submission status: Wrong Answer

Solution code:
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(len(a[0]) - len(b[0]) + 1):
        for k in range(m):
            if a[i+k][j:(j+m)] != b[k]:
                break
            print('Yes')
            quit()
print('No')

Submission status: Wrong Answer

Solution code:
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(len(a[0]) - len(b[0]) + 1):
        for i in range(m):
            if a[i][i:(i+m)] != b[i]:
                break
            print('Yes')
            quit()
print('No')

Submission status: Wrong Answer

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

a = []
b = []

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

for i in range(n*n):
    SPRow,SPColumn = divmod(i,n)
    if SPRow + m <= n-1 and SPColumn + m <= n-1:
        for j in range(m*m):
            MPRow,MPColumn = divmod(j,m)

            if a[SPRow + MPRow][SPColumn + MPColumn] == b[MPRow][MPColumn]:
                if MPRow == (m-1) and MPColumn == (m-1):
                    OKFlag = True
                continue
            else:
                break
    else:
        continue
print("Yes" if OKFlag else "No")