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:
def solve(n, m, NUM):
    for i in range(len(m)):
        if n[NUM + i] is not m[i]:
            return -1
    return 1


N, M = [int(i) for i in input().split()]
n_pic = [input() for i in range(N)]
m_pic = [input() for i in range(M)]
num = 0
if M is 1:
    for n in n_pic:
        if -1 is not n.find(m_pic[0]):
            print('Yes')
            exit()
    print('No')
    exit()

for n in n_pic:
    for n_len in range(N - M + 1):
        while -1 is not solve(n, m_pic[num], n_len):
            num += 1
            if num is M - 1:
                print('Yes')
                exit()
        num = 0
print('No')

Submission status: Wrong Answer

Solution code:
n,m=[int(x) for x in input().split()]
a=[]
b=[]
for i in [0]*n:
    a.append(input())
for i in [0]*m:
    b.append(input())
def check(x,y):
    for i in range(m):
        if a[y+i][x:x+m] != b[i]:
            return False
    return True
from itertools import product
for i,j in product(range(n-m),range(n-m)):
    if check(i,j):
        print("Yes")
        import sys
        sys.exit()
print("No")

Submission status: Wrong Answer

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

A=[]
B=[]

for i in range(N):
    a=input()
    A.append(a)
    
for j in range(M):
    b=input()
    B.append(b)
    
for k in range(M-1):
    if B[k] in A[k] and B[k+1] in A[k+1]:
        print('Yes')
        break
        

else:
    print('No')

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [0]*N
B = [0]*M

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

ans = False
for sy in range(N-M):
	for sx in range(N-M):
		flag = True
		for iy in range(M):
			if B[iy] != A[sy+iy][sx:sx+M]:
				flag = False
				break
		if flag:
			ans = True
			break

if ans:
	print("Yes")
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)]

res = False
count = 0
for i in range(N - M + 1):
    if count == M:
        res = True
        break
    for j in range(N - M + 1):
        if count == M:
            res = True
            break
        count = 0
        for m in range(M):
            if A[i + m][j:j + M] != B[m]:
                res = False
                break
            else:
                count += 1

if res:
    print("Yes")
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)]

res = False
count = 0
for i in range(N - M + 1):
    for j in range(N - M + 1):
        count = 0
        for m in range(M):
            if A[i + m][j:j + M] != B[m]:
                res = False
                break
            else:
                count += 1
        if count == M:
            res = True
            break
            

if res:
    print("Yes")
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)]

res = False

for i in range(N - M + 1):
    for j in range(N - M + 1):
        count = 0
        for m in range(M):
            if A[i + m][j:j + M] != B[m]:
                res = False
                break
            else:
                count += 1
        if count == M:
            res = True


if res:
    print("Yes")
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)]

res = False

for i in range(N-M+1):
    for j in range(N-M+1):
        for m in range(M):
            if A[i+m][j:j+M] != B[m]:
                res = False
                break
            else:
                res = True

if res:
    print("Yes")
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)]

res = False

for i in range(N-M+1):
    for j in range(N-M+1):
        for m in range(M):
            if A[i+m][j:j+M] == B[m]:
                res = True
            else:
                res = False
                break

if res:
    print("Yes")
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)]

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

Submission status: Wrong Answer

Solution code:
import sys
N,M=map(int,input().split())
A=[]
B=[]
A+=[str(input()) for i in range(N)]
B+=[str(input()) for i in range(M)]
for i in range(N-M):
  for j in range(N-M):
    ans=1
    for k in range(M):
      for l in range(M):
        if B[k][l]!=A[i+k][j+l]:
          ans=0
    if ans:
      print("Yes")
      sys.exit()
print("No")

Submission status: Wrong Answer

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

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

for i in range(N-M-1):
    for j in range(N-M-1):
        diff = 0

        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    diff = 1
                    break

            if diff == 1:
                break

        if diff == 0:
            print('Yes')
            sys.exit()

print('No')

Submission status: Wrong Answer

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

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

for i in range(N-M):
        for j in range(N-M):
            diff = 0

            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        diff = 1
                        break

                if diff == 1:
                    break

            if diff == 0:
                print('Yes')
                sys.exit()


print('No')

Submission status: Wrong Answer

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

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

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

                if diff == 1:
                    break

            if diff == 0:
                print('Yes')
                sys.exit()


print('No')

Submission status: Wrong Answer

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

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

diff = 0

for i in range(N-M):
        for j in range(N-M):

            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        diff = 1
                        break

                if diff == 1:
                    break

            if diff == 0:
                print('Yes')
                sys.exit()


print('No')

Submission status: Wrong Answer

Solution code:
def bsolve(a,b,c,d):
	M=len(b)
	for i in range(M):
		for j in range(M):
			if(a[c+i][d+j]!=b[i][j]):
				print(a[c+i][d+j],b[i][j])
				return int(0)
	return int(1)
def b():
	N,M=list(map(int,input().split()))
	A=[input()for _ in range(N)]
	B=[input()for _ in range(M)]
	flag=0
	for i in range(N-M+1):
		for j in range(N-M+1):
			if(A[i][j]==B[0][0]):
				flag=bsolve(A,B,i,j)
				if(flag==1):
					print("Yes")
					return 
	if(flag==1):
		print("Yes")
		return 
	else:
		print("No")
		return
b()

Submission status: Wrong Answer

Solution code:
def slv():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

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

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

    y = []
    for i in range(0, n):
        for j in range(i, m):
            if a[j].find(b[j]) != -1:
                y.append(a[j].find(b[j]))

        if len(set(y)) == 1 and len(y) == m:
            print("Yes")
            return 0
        y = []
if slv() != 0:
    print("No")

Submission status: Wrong Answer

Solution code:
def slv():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

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

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

    y = []
    for i in range(0, n):
        for j in range(i, m):
            if a[j].find(b[j]) != -1:
                y.append(a[j].find(b[j]))

        if len(set(y)) == 1 or len(y) == m:
            print("Yes")
            return 0
        y = []
if slv() != 0:
    print("No")

Submission status: Wrong Answer

Solution code:
def slv():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

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

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

    y = []
    for i in range(0, n):
        for j in range(i, m):
            if a[j].find(b[j]) != -1:
                y.append(a[j].find(b[j]))

        if len(set(y)) == 1:
            print("Yes")
            return 0
        y = []
if slv() != 0:
    print("No")

Submission status: Wrong Answer

Solution code:
def slv():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

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

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

    y = []
    for i in range(0, n):
        for j in range(i, m):
            if a[j].find(b[j]) != -1:
                y.append(a[j].find(b[j]))

        if len(y) == m:
            if len(set(y)) == 1:
                print("Yes")
                return 0
        y = []
if slv() != 0:
    print("No")

Submission status: Wrong Answer

Solution code:
def slv():
    x = list(map(int, input().split()))
    n = x[0]
    m = x[1]

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

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

    y = []
    for i in range(0, n):
        for j in range(i, m):
            if a[j].find(b[j]) != -1:
                y.append(a[j].find(b[j]))
        for k in range(0, len(y)):
            if y[k] == -1:
                continue
        if len(y) == m:
            if len(set(y)) == 1:
                print("Yes")
                return 0
        y = []
if slv() != 0:
    print("No")

Submission status: Wrong Answer

Solution code:
N , M = map(int , input().split())
A = []
B = []
flg = []

for i in range(N):
    A.append([j for j in input()])
for i in range(M):
    B.append([j for j in input()])

for i in range(N-M):
    for k in range(N-M):
        for j in range(M):
            for l in range(M):
                if B[j][l] != A[j+i][l+k]:
                    flg.append(0)
                    
            
 
if 0 in flg:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N , M = map(int , input().split())
A = []
B = []
flg=True

for i in range(N):
    A.append([j for j in input()])
for i in range(M):
    B.append([j for j in input()])

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

Submission status: Wrong Answer

Solution code:

N, M = map(int, input().split())
A = []
for i in range(N):
	A.append(input())
B = []
for i in range(M):
	B.append(input())
t = 0
for i in range(N-M):
	for j in range(N-M):
		t = 0
		for k in range(M):
			if t:
				break
			for l in range(M):
				if A[i+k][j+l] != B[k][l]:
					t = 1
					break
		else:
			if A[i+k][j+l] == B[k][l]:
				print("Yes")
				exit()
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 i in range(M):
    B.append(list(input()))

result = True
find = False
for i in range(N-M):
    for j in range(N-M):
        if A[i][j] == B[0][0]:
            result = True
            for k in range(M):
                if result:
                    for l in range(M):
                        if A[i+k][j+l] == B[k][l]:
                            continue
                        else:
                            result = False
                            break
                else:
                    break
                if k == M-1:
                    find = True
        if find:
            break
    if find:
        break

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

Submission status: Wrong Answer

Solution code:
size = list(map(int,raw_input().split()))

large_pic=[]
small_pic=[]
for i in range (size[0]):
    large_pic.append (list(raw_input().strip()))
for i in range (size[1]):
    small_pic.append (list(raw_input().strip()))


flag = False
cut_pic = []
for i in range (size[0]-size[1]):
    for j in range (size[0]-size[1]):
        for k in range (size[1]):
            cut_pic.append(large_pic[i+k][j:j+size[1]])
        if cut_pic == small_pic:
            flag = True
        else:
            cut_pic =[]
print "Yes" if flag == True else "No"

Submission status: Wrong Answer

Solution code:
size = list(map(int,raw_input().split()))

large_pic=[]
small_pic=[]
for i in range (size[0]):
    large_pic.append (list(raw_input().strip()))
for i in range (size[1]):
    small_pic.append (list(raw_input().strip()))

print large_pic
print small_pic

flag = False
cut_pic = []
for i in range (size[0]-size[1]):
    for j in range (size[0]-size[1]):
        for k in range (size[1]):
            cut_pic.append(large_pic[i+k][j:j+size[1]])
        if cut_pic == small_pic:
            flag = True
        else:
            cut_pic =[]
print "Yes" if flag == True else "No"

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import numpy as np


def main():
    # 入力処理
    # M = int(input())
    N, M = map(int, input().split())
    sA = ''.join([input() for i in range(N)])
    sB = ''.join([input() for i in range(M)])
    A = np.array([s for s in sA]).reshape(N,N)
    B = np.array([s for s in sB]).reshape(M,M)

    # アルゴリズム本体
    result = np.zeros((N-M,N-M), dtype=bool)
    for i in range(N-M):
        for j in range(N-M):
            result[i,j] = (A[i:i+M, j:j+M] == B).all()

    # 出力
    if result.any():
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import re

first_line = input().split()
n = int(first_line[0])
m = int(first_line[1])

n_list = []
for i in range(n):
    n_list.append(input())
m_list = []
for i in range(m):
    m_list.append(input())

match_flg = False
for i in range(0, n - m + 1):
    matchOb = re.match(m_list[0], n_list[i])
    if matchOb:
        start_pos = matchOb.start()
        end_pos = matchOb.end()
        for j in range(0, m):
            if n_list[i + j][start_pos:end_pos] == m_list[j] and j == m - 1:
                match_flg = True
            elif n_list[i + j][start_pos:end_pos] != m_list[j]:
                break

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

Submission status: Wrong Answer

Solution code:
import re

first_line = input().split()
n = int(first_line[0])
m = int(first_line[1])

n_list = []
for i in range(n):
    n_list.append(input())
m_list = []
for i in range(m):
    m_list.append(input())

match_flg = False
for i in range(0, n - m):
    matchOb = re.match(m_list[0], n_list[i])
    if matchOb:
        start_pos = matchOb.start()
        end_pos = matchOb.end()
        for j in range(1, m):
            if n_list[i + j][start_pos:end_pos] == m_list[j] and j == m - 1:
                match_flg = True
            elif n_list[i + j][start_pos:end_pos] != m_list[j]:
                break

if match_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(input())
for j in range(M):
    B.append(input())

flag = False
for i in range(N-M+1):
    index = A[i].find(B[0])
    if index != -1:
        print(i, index)
        flag = True
        for j in range(1, M):
            for k in range(M):
                if A[i+j][index+k] != B[j][k]:
                    flag = False
                    break
        if flag == False:
            break
    if flag == True:
        print("Yes")
        break
if flag == False:
    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 j in range(M):
    B.append(input())

flag = False
for i in range(N-M):
    index = A[i].find(B[0])
    if index != -1:
        flag = True
        for j in range(1, M):
            for k in range(M):
                if A[i+j][index+k] != B[j][k]:
                    flag = False
                    break
        if flag == False:
            break
    if flag == True:
        print("Yes")
        break
if flag == False:
    print("No")

Submission status: Wrong Answer

Solution code:
def main():
    nm = map(int, raw_input().split())
    A = []
    B = []
    flag = False
    for i in range(nm[0]):
        A.append(raw_input())
    for i in range(nm[1]):
        B.append(raw_input())

    for i in range(nm[0]):
        if i + nm[1] <= nm[0]:
         for j in range(nm[0]):
            if j + nm[1] <= nm[0]:
                for k in range(nm[1]):
                    for l in range(nm[1]):
                        if(A[i+k][j+l] == B[k][l]):
                            flag = True
                        else:
                            flag = False
                            break 
                    if flag == False:
                        break
            if flag:
                 break
        if flag:
            break
    if flag:
        return "yes"
    else:
        return "no"    
print main()

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

ans = 0
for i in range(N-M+1):
    for j in range(N-M):
        t = [k[j:j+M] for k in a[i:i+M]]
        if t==b: ans =1

print("Yes" if ans else "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 check(i,j):
    for row in range(m):
        for col in range(m):
            if a[row + i][col + j] == b[row][col]:
                return True

    return False
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: 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 check(i,j):
    for row in range(m):
        for col in range(m):
            if a[row + i][col + j] == b[row][col]:
                return True

    return False
for i in range(n-m+1):
    for j in range(n-m+1):
        if check(i,j):
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
n,m = map(int, raw_input().split())
np=[]
mp=[]
for i in xrange(0, n):
  np.append(raw_input())
for i in xrange(0, m):
  mp.append(raw_input())

for i in xrange(0,n-m+1):
  for j in xrange(0, n-m+1):
    flag = True
    for x in xrange(0, m):
      for y in xrange(0, m):
        if mp[x][y] != np[i+x][j+y]:
          flag = False
          break
      if flag == False:
        break
    if flag:
      print "Yes"
      break
  if flag: break
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 = 0
for i in range(n - m + 1):
    for j in range(n - m + 1):
        t = [k[j:j + m] for k in a[i:i + m]]
        if t == b: f = 1

print ("Yes" if f else "no")

Submission status: Wrong Answer

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

for i in range(0,N-M+1):
    for j in range(0,N-M+1):
        cnt = 0
        for k in range(0,M):
            for l in range(0,M):
                if A[i+k][j+l] == B[k][l]:
                    cnt = cnt + 1
        if cnt == M*M:
            break
if cnt == M*M:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
a,b = [],[]
for i in range(N):
    a.append(input())
for i in range(M):
    b.append(input())

d = N - M
match = False
for i in range(d):
    for j in range(d):
        if a[i:i+M-1][j:j+M-1]:
            match = True
            break
    if match == True:
        break
if match == True:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
a,b = [],[]
for i in range(N):
    a.append(input())
for i in range(M):
    b.append(input())

d = N - M
match = False

for i in range(d):
    match = True
    for j in range(d):
        match = True
        for k in range(M):
            if b[k] != a[i+k][j:N-d+j]:
                match = False
                break
        if match == True:
            break
    if match == True:
        break
if match == True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
a,b = [],[]
for i in range(N):
    a.append(input())
for i in range(M):
    b.append(input())

d = N - M
match = False
for j in range(d):
    match = True
    for i in range(M):
        if b[i] != a[i][j:N-d+j]:
            match = False
            break
    if match == True:
        break
if match == True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N,M = list(map(int,input().split()))
a,b = [],[]
for i in range(N):
    a.append(input())
for i in range(M):
    b.append(input())

d = N - M
match = False
for j in range(d):
    match = True
    for i in range(d):
        if b[i] != a[i][j:N-d+j]:
            match = False
            break
    if match == True:
        break
if match == True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

N, M = [], []
for i in range(n):
    N.append(list(input()))
for i in range(m):
    M.append(list(input()))

# print(N)
# print(M)

def check():
    for i in range(n-m+1):
        for j in range(n-m+1):
            flag = True
            for ii in range(m):
                for jj in range(m):
                    flag &= N[i+ii][j+jj] == M[ii][jj]
                    if not flag:
                        return "No"
            if flag:
                return "Yes"
    return "No"

print(check())

Submission status: Wrong Answer

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

N, M = [], []
for i in range(n):
    N.append(list(input()))
for i in range(m):
    M.append(list(input()))

# print(N)
# print(M)

def check():
    for i in range(n-m+1):
        for j in range(n-m+1):
            flag = True
            for ii in range(m):
                for jj in range(m):
                    flag &= N[i+ii][j+jj] == M[ii][jj]
                    if not flag:
                        return "No"
            if flag:
                return "Yes"

print(check())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
A = []
B = []
N, M = list(map(int, input().split()))

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

def match(r, c):
    for i, row in enumerate(range(r, r+M)):
#        print("{} : {}  {}".format(A[row][c:c+M], B[i], A[row][c:c+M]==B[i]))
        if A[row][c:c+M] != B[i]:
            return False
    return True

ok = 0

for r in range(N-M+1):
    if ok == 1:
        break
    else:
        for c in range(N-M+1):
            if match(r, c):
                print("YES")
                ok = 1
                break
            
if not ok:
    print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
A = []
B = []
N, M = list(map(int, input().split()))

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

def match(r, c):
    for i, row in enumerate(range(r, r+M)):
        if A[row][c:c+M] != B[i]:
            return False
    return True

ok = 0

for r in range(N-M+1):
    if ok == 0:
        for c in range(N-M+1):
            if match(r, c):
                print("YES")
                ok = 1
            
if not ok:
    print("No")

Submission status: Wrong Answer

Solution code:
_N, _M = input().split()
N=int(_N)
M=int(_M)
A=[]
for i in range(0,N):
    A.append(input())
B=[]
for j in range(0,M):
    B.append(input())

ref_tuple = zip(range(0,N-M+1),range(0,N-M+1))
t=False
for ref_row_a, ref_col_a in ref_tuple:
    for row_b, col_b in zip(range(0,M),range(0,M)):
        if not A[ref_row_a+row_b][ref_col_a+col_b]==B[row_b][col_b]:
            break
        if (row_b, col_b)==(M-1,M-1):
            t=True
            break
    if t:
        break

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

Submission status: Wrong Answer

Solution code:
n,m = map(int, raw_input().split())
aa = [0] * n
bb = [0] * m
for i in range(n):
    aa[i] = list(raw_input())
for i in range(m):
    bb[i] = list(raw_input())

flag = True
for i in range(n-m):
    for j in range(n-m):
        flag = True
        for ik in range(m):
            for jk in range(m):
                if aa[i+ik][j+jk] != bb[ik][jk]:
                    flag = False
                    
        if flag == True: break
    if flag == True: break

if flag == True:
    print 'YES'
else:
    print 'NO'

Submission status: Wrong Answer

Solution code:
# -*- coding:utf8

N,M = [int(x) for x in raw_input().split(' ')]

A = [raw_input() for x in range(N)]
B = [raw_input() for x in range(M)]

def getpattern(image, s = 0, x = 0, y = 0):
    if s == 0:
        s = len(image)

    return ''.join([image[i][x:x+s] for i in range(y, y + s)])

def match(N,M,A,B):
    size = len(B)

    bpattern = getpattern(B)
    for j in range(0, N - len(B)):
        for i in range(0, N - len(B)):
            if getpattern(A, size, i, j) == bpattern:
                return 'Yes'

    return 'No'

print match(N,M,A,B)

Submission status: Wrong Answer

Solution code:
def srch_all(ptn, str):
    index = []
    i = -1
    while True:
        i = str.find(ptn, i + 1)
        if i > -1:
            index.append(i)
        else:
            break
    return index

def judge(i, jlist, len):
    print(jlist)
    for l in jlist:
        k = 1
        while k < M:
            try:
                if n[i + 1][l:l + len] == m[k]:
                    pass
                else:
                    return 'No'
            except:
                return 'No'
            k += 1
        else:
            return 'Yes'

N, M = map(int, input().split())
i = 0
n = []
while i < N:
    n.append(input())
    i += 1

i = 0
m = []
while i < M:
    m.append(input())
    i += 1

i = 0
r = 'No'
while i < N:
    result = srch_all(m[0], n[i])
    if len(result) > 0:
        r = judge(i, result, len(m[0]))
        if r == 'Yes':
            break
    i += 1
print(r)

Submission status: Wrong Answer

Solution code:
import sys

A=[]
B=[]
NM=input().split(" ")
N=int(NM[0])
M=int(NM[1])

for i in range(N):
    t=input()
    A.append(t)
for i in range(M):
    t=input()
    B.append(t)



for i in range(N-M+1):
    for j in range(N-M+1):
        k=i
        count=0
        while A[k+count][i:i+M:1]==B[count]:
            count+=1
            if count==M:
                print("Yes")
                sys.exit()

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


def f():
    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:
                return True
    return False

print("Yes" if f() 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)]


def f():
    for i in range(n - m):
        for j in range(n - m):
            flag = True
            for k in range(m):
                if a[i + k][j:j + m] != b[k]:
                    flag = False
                    break
            else:
                return True
            if flag == False:
                continue
    return False

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def is_matched(sq1, sq2):
    for i in range(len(sq1)):
        for j in range(len(sq1)):
            if sq1[i][j] != sq2[i][j]:
                return False
    return True

NM = map(int, raw_input().split())

N_square = [map(str, raw_input()) for i in range(NM[0])]
M_square = [map(str, raw_input()) for i in range(NM[1])]

for i in range(NM[1]):
    for j in range(NM[1]):
        if is_matched(N_square[i:i+NM[1]], M_square):
            print "Yes"
            exit()

print "No"