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:
n, m = map(int, input().split())
a = list()
for _ in range(n):
    a.append(str(input()))
b = list()
for _ in range(m):
    b.append(str(input()))

for H in range(n if m == 1 else n-m+1):
    for W in range(n if m == 1 else n-m+1):
        for M in range(m):
            cnt = 0
            if a[H+M][0+W:m+W] == b[M]:
                cnt+=1
        if cnt==m:
            print('Yes')
            exit()

print('No')

Submission status: Wrong Answer

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

for H in range(n if m == 1 else n-m+1):
    for W in range(n if m == 1 else n-m+1):
        for M in range(m):
            if a[H+M][0+W:m+W] == b[M]:
                print('Yes')
                exit()

print('No')

Submission status: Wrong Answer

Solution code:
def main():

    n,m = map(int,input().split())
    a = []
    for i in range(n):
        aa = list(input())
        a.append(aa)
    b = []
    for i in range(m):
        bb = list(input())
        b.extend(bb)
    
    for i in range(n-m+1):
        for j in range(n-m+1):
            tmp_a = []
            for k in range(i+m):
                tmp_a.extend(a[k][j:j+m])
            if b == tmp_a:
                print('Yes')
                return
    print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
a = []
b = []
for i in range(n):
    a.append(ins())
for i in range(m):
    b.append(ins())
for i in range(n-m):
    for j in range(n-m):
        ok = True
        for k in range(m):
            if a[i+k][j:j+m]!=b[k]:
                ok = False
                break
        if ok:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

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

al = [list(input()) for _ in range(n)]
bl = [list(input()) for _ in range(m)]

def same(h,w):
    for hi in range(m):
        for wi in range(m):
            if al[h+hi][w+wi]!=bl[hi][wi]:
                return False
    return True


for hi in range(n-m):
    for wi in range(n-m):
        if same(hi,wi):
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np


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

for i in range(n-m+1):
    for j in range(n-m+1):
        if np.all(a[i:i+m, j:j+m] == b):
            flug =1

ans = 'Yes' if flug else 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
n, m, *d = open(0).read().split()
n, m = int(n), int(m)
r = range(n - m + 1)
print(["No","Yes"][all(d[n:] == [t[j:j+m] for t in d[i:i+m]] for i in r for j in r)])

Submission status: Wrong Answer

Solution code:
n, m, *d = open(0).read().split()
n, m = int(n), int(m)
r = range(n - m + 1)
print(["No","Yes"][all(d[n:] == [t[j:j+m] for t in d[i:i+m]] for i in r for j in r)::2])

Submission status: Wrong Answer

Solution code:
# ABC 054: B – Template Matching
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

isIncluding = 'No'
current = 0

for i in range(n):
    if b[0] in a[i]:
        current = a[i].index(b[0])

        if i + m > n:
            break

        for j in range(1, m):
            if b[j] not in a[i + j]or  a[i + j].index(b[j]) != current:
                break
        else:
            isIncluding = 'Yes'
            break

print(isIncluding)

Submission status: Wrong Answer

Solution code:
# ABC 054: B – Template Matching
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

isIncluding = 'No'
current = 0

for i in range(n - m):
    if b[0] in a[i]:
        current = a[i].index(b[0])

        for j in range(1, m):
            if b[j] not in a[i + j] or a[i + j].index(b[j]) != current:
                break
        else:
            isIncluding = 'Yes'
            break

print(isIncluding)

Submission status: Wrong Answer

Solution code:
# ABC 054: B – Template Matching
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

isIncluding = 'No'

for p in a:
    for q in b:
        if q not in p:
            break
    else:
        isIncluding = 'Yes'
        break
        
print(isIncluding)

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

temp = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        for row in range(M):
            for col in range(M): 
                if A[i+row][j+col] == B[row][col]:
                    temp +=1
                    if temp == M*M:
                        print('Yes')
                        exit()
                else:
                    temp = 0
        break
            
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)]

temp = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        for row in range(M):
            for col in range(M): 
                if A[i+row][j+col] == B[row][col]:
                    temp +=1
                    print(temp)
                    if temp == M*M:
                        print('Yes')
                        exit()
                else:
                    temp = 0
        break
            
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)]

temp = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        for row in range(M):
            for col in range(M): 
                if A[i+row][j+col] == B[row][col]:
                    temp +=1
                if temp == M*M:
                    print('Yes')
                    exit()
                else:
                    temp = 0
        break
            
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)]

temp = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        for row in range(M):
            for col in range(M): 
                if A[i+row][j+col] == B[row][col]:
                    temp +=1
                elif temp == M*M:
                    print('Yes')
                    exit()
                else:
                    temp = 0
        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)]
for i in range(n-m):
  for k in range(n-m):
    if all(b[j] in a[i+j][k:k+m+1] for j in range(m)):
      print('Yes')
      exit()
print('No')

Submission status: Wrong Answer

Solution code:
from sys import exit

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

def valid(i, j):
    for a, b in zip(A[i:i+M], B):
        if a[j:j+M] == b:
            continue
        else:
            return False
    return True

for i in range(N-M):
    for j in range(N-M):
        if valid(i, j):
            print("Yes")
            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)]

fileter = ''
index = -1
for i in range(n):
    for j in range(m):
        if b[j] in a[i]:
            check = True
            if fileter != b[j] and index == a[i].index(b[j]):
                print('Yes')
                quit()
            index = a[i].index(b[j])
            fileter = b[j]

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)]
x=0
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            if a[i][j]==b[k][0]:
                for l in range(m):
                    if a[i][j+l]==b[k][l]:x+=1
if x==m:print('Yes')
else:print('No')

Submission status: Wrong Answer

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

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


for i in range(N - M):
    for j in range(N - M):
        br = False
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    br = True
                    break
            if br:
                break
        if not br:
            print("Yes")
            exit()


print("No")

Submission status: Wrong Answer

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

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


for i in range(N - M):
    for j in range(N - M):
        br = False
        for k in range(M):
            for l in range(M):
                if A[i + k][j + l] != B[k][l]:
                    br = True
                    break
            if br:
                break
    if not br:
        print("Yes")
        exit()


print("No")

Submission status: Wrong Answer

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

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


for i in range(N - M):
    br = False
    for j in range(M):
        for k in range(N - M):
            for l in range(M):
                if A[i + j][k + l] != B[j][l]:
                    br = True
                    break
    if not br:
        print("Yes")
        exit()


print("No")

Submission status: Wrong Answer

Solution code:
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7
def main():
  n,m = map(int,input().split())
  A = [input() for _ in range(n)]
  B = [input() for _ in range(m)]
  
  for i in range(m):
    if A[i][:len(B[i])] == B[i]:
      pass
    else:
      print('No')
      exit()
  print('Yes')
  
  
if __name__ == '__main__':
  main()

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)]
ans = 'No'
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
        if ok: ans = 'Yes'
print(ans)

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-M):
  for j in range(N-M):
    x = []
    for k in range(M):
      for l in range(M):
        x.append(A[i+k][j+l])
    if ''.join(x) == ''.join(B):
      print("Yes")
      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)]

for i in range(N-M):
  for j in range(N-M):
    x = []
    y = []
    for k in range(M):
      x.append(A[i][j+k])
      y.append(A[i+k+1][j])
    x.extend(y)
    if ''.join(x) == ''.join(B):
      print("Yes")
      exit()

print("No")

Submission status: Wrong Answer

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

c = 0

for i in range(n-m+1):
  if set(a[i:i+m]) == set(b[:m]):
    c += 1
  else:
    c += 0

if c > 0:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

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

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

existed = False
for i in range(N - M):
  for j in range(N - M):
    match = True
    for mi in range(M):
      for mj in range(M):
        x = i + mi
        y = j + mj

        if (A[y][x] != B[mj][mi]):
          match = False
          break
      
      if (match == False):
        break

    if (match):
      existed = True
      break
  
  if (existed):
    break

result = 'Yes' if (existed) else 'No'
print(result)

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

is_ok = False
for dx in range(n-m+1):
    for dy in range(n-m+1):
        f = True
        for y in range(m):
            for x in range(m):
                if a[y+dy][x+dx] != b[y][x]:
                    f = False

        is_ok = f

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

is_ok = False
for dx in range(n-m):
    for dy in range(n-m):
        f = True
        for y in range(m):
            for x in range(m):
                if a[y+dy][x+dx] != b[y][x]:
                    f = False

        is_ok = f

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

Submission status: Wrong Answer

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

A = [input().strip() for _ in range(N)]
B = [input().strip() for _ in range(M)]
temp = "".join(B)


ans = False

for j in range(N-M+1):
    for i in range(N-M+1):
        tmp = ""
        for y in range(M):
            tmp += A[y][i: i + M]
        if tmp == temp:
            ans = True

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

Submission status: Wrong Answer

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
#template
#issueから始める
import re
N,M = inputlist()
A = ['0']*N
B = ['0']*M
for i in range(N):
    A[i] = input()
for i in range(M):
    B[i] = input()
for i in range(N-M+1):
    if B[0] in A[i]:
        count = 1
        m = re.search(B[0],A[i])
        st = m.start()
        en = m.end()
        for j in range(1,M):
            if A[i+j][st:en] == B[j]:
                count+=1
        if count == M:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

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

c = 0

for i in range(m-1):
	for j in range(n-1):
		if set(a[i]) == set(b[j]) & set(a[i+1]) == set(b[j+1]):
			c += 1
            
if c > 0:
  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)]
#print(a,b)
ans=0
cnt=0
for i in range(n-m+1):
  for j in range(n-m+1):
    cnt=0
    for k in range(m):
      if b[k]!=a[i+k][j:j+m]:
        break
      cnt+=1
      #print(a[i+k][j:j+m],b[k],a[i+k][j:j+m]==b[k])
    if cnt==m:
      ans+=1
    if ans>0:
      break
  if ans>0:
    break
  
print("Yes" if ans>0 else "No",ans)

Submission status: Wrong Answer

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

diff = N-M
for di in range(diff):
    for dj in range(diff):
        flag = True
        for i in range(M):
            for j in range(M):
                if B[i][j] != A[i+di][j+dj]:
                    flag = False
                    break

            if flag==False:
                break
            
        if flag:
            print('Yes')
            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)]

diff = N-M

for d in range(diff):
    for i in range(M):
        for j in range(M):
            flag = True
            if B[i][j] != A[i+d][j+d]:
                flag = False
                break
        
        if flag:
            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(input())
for i in range(m):
	b.append(input())

check = False
for i in range(n):

	if b[0]in a[i]:
		index=a[i].index(b[0])
		check=True
		for k in range(m):
			if i+k>=n:
				check=False
				break

			if  b[k] not in a[i+k]:# or a[i+k].index(b[k])!=index:
				check=False
				break

	if check:
		break

print("Yes" if check 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 i in range(m):
	b.append(input())

check = False
for i in range(n):

	if b[0]in a[i]:
		index=a[i].index(b[0])
		check=True
		for k in range(m):
			if i+k>=n:
				check=False
				break

			if not b[k]in a[i+k]:# or a[i+k].index(b[k])!=index:
				check=False
				break

	if check:
		break

print("Yes" if check 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 i in range(m):
	b.append(input())

check = False
for i in range(n):

	if b[0]in a[i]:
		index=a[i].index(b[0])
		check=True
		for k in range(m):
			if i+k>=n:
				check=False
				break

			if not b[k]in a[i+k] or a[i+k].index(b[k])!=index:
				check=False
				break

	if check:
		break

print("Yes" if check 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 i in range(m):
	b.append(input())

check = False
for i in range(n):

	if b[0]in a[i]:
		index=a[i].index(b[0])
		check=True
		for k in range(m):
			if i+k>=n:
				check=False
				break

			if not b[k]in a[i+k] or a[i+k].index(b[k])!=index:
				check=False
				break
	if check:
		break

print("Yes" if check 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 i in range(m):
	b.append(input())

check = False
for i in range(n):

	if b[0]in a[i]:
		index=a[i].index(b[0])
		check=True
		for k in range(m):
			if i+k>=n:
				break
			if not b[k]in a[i+k] or ( a[i+k].index(b[k])!=index):
				check=False
				break
	if check:
		break

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

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
list_A = list(input() for i in range(n))
list_B = list(input() for i in range(m))
k = "No"
for i in range(n-m+1):
  for t in range(n-m+1):
      if any( list_A[v+i][t:t+m]!=list_B[v] for v in range(m)):
        break
      k = "Yes"
print(k)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
list_A = list(input() for i in range(n))
list_B = list(input() for i in range(m))
print(list_A)
print(list_B)
k = "No"
for i in range(n-m+1):
  for t in range(n-m+1):
      if any( list_A[v+i][t:t+m]!=list_B[v] for v in range(m)):
        break
      k = "Yes"
print(k)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
list_A = list(input() for i in range(n))
list_B = list(input() for i in range(m))
k = "No"
for i in range(n-m+1):
  for t in range(n-m+1):
    for v in range(m):
      if list_A[v+i][t:t+m]!=list_B[v]:
        break
      k = "Yes"
      break
print(k)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
list_A = list(input() for i in range(n))
list_B = list(input() for i in range(m))
k = "No"
for i in range(n-m+1):
  for t in range(n-m+1):
    for v in range(m):
      if list_A[v+i][t:t+m]!=list_B[v][0:m]:
        break
      k = "Yes"
      break
print(k)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
list_A = list(input() for i in range(n))
list_B = list(input() for i in range(m))
k = "No"
for i in range(n-m+1):
  for t in range(n-m+1):
    for v in range(m):
      if list_A[v+i][t:t+m]!=list_B[v][0:m]:
        break
      k = "Yes"
print(k)

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [[i for i in input()] for _ in range(n)]
b = [[i for i in input()] for _ in range(m)]
com = True
for h in range(n-m+1):
    for w in range(n-m+1):
        for hi in range(m):
            for wi in range(m):
                print(a[h+hi][w+wi], b[hi][wi])
                if a[h+hi][w+wi] != b[hi][wi]:
                    com = False
        if com:
            print("Yes")
            exit()
        else:
            com = True
print("No")

Submission status: Wrong Answer

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

def init_img(n):
    return [[0 if j == "#" else 1 for j in input()] for i in range(n)]

img = init_img(n)

tmp_img = init_img(m)

flg = False

for i in range(0, n):
    if flg:
        break

    for j in range(0, n):
        if i+1 < n and j+1 < n:
            if img[i][j:j+2] == tmp_img[0] and img[i+1][j:j+2] == tmp_img[1]:
                flg = True
                break
if flg:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

As = np.array([["." for n in range(N)] for nn in range(N)])
for n in range(N):
  As[n,:] = np.array(list(input()))
  
Bs = np.array([["." for n in range(M)] for nn in range(M)])
for m in range(M):
  Bs[m,:] = np.array(list(input()))
  
ok = False
for i in range(N-M+1):
  for j in range(N-M+1):
    print(As[i:i+M,j:j+M])
    print()
    if (As[i:i+M,j:j+M] == Bs).all():
      ok = True
      break
if ok:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

As = np.array([["." for n in range(N)] for nn in range(N)])
for n in range(N):
  As[n,:] = np.array(list(input()))
  
Bs = np.array([["." for n in range(M)] for nn in range(M)])
for m in range(M):
  Bs[m,:] = np.array(list(input()))
  
ok = False
for j in range(N-M):
    if (As[:M,j:j+M] == Bs).all():
      ok = True
      break
if ok:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

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

As = np.array([["." for n in range(N)] for nn in range(N)])
for n in range(N):
  As[n,:] = np.array(list(input()))
  
Bs = np.array([["." for n in range(M)] for nn in range(M)])
for m in range(M):
  Bs[m,:] = np.array(list(input()))
  
ok = False
for i in range(N-M):
  for j in range(N-M):
    if (As[i:i+M,j:j+M] == Bs).all():
      ok = True
      break
if ok:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
S =list(map(int,input().split()))
N=S[0]
M=S[1]

la=[]
for i in range(N):
    la.append(input())
lb=[]
for i in range(M):
    lb.append(input())


for i in range(N-M+1):
    for j in range(N-M+1):
        flag=True
        for k in range(M):
            for l in range(M):
                if la[i+k][j+l]!=lb[k][l]:
                    flag ==False
        if flag==True:
            print("Yes")
            exit()
print("No")

Submission status: Wrong Answer

Solution code:
#ABC054.B
N,M = map(int,input().split())
for _ in range(N):
    A = input()
for _ in range(M):
    B = input()
if B in A:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[input() for i in range(n)]
ml=[input() for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    for h in range(m):
      if ml[h]!=l[i][j:j+m]:break
    else: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)]
d = n - m + 1
flag = True

for k in range(d):
    for i in range(d):
        for j in range(m):
            for l in range(m):
                flag = True
                if A[k + j][i + l] != B[j][l]:
                    flag = False
                    break

            if flag == False:
                break

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

Submission status: Wrong Answer

Solution code:
import sys

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

a_list = [[l for l in input()] for _ in range(n)]
b_list = [[l for l in input()] for _ in range(m)]

for i in range(n-m):
    for j in range(n-m):
        a_list_sub = a_list.copy()
        a_list_sub = a_list[i:i+m]
        a_list2 = [row[j:j+m] for row in a_list_sub]
        if a_list2 == b_list:
            print('Yes')
            sys.exit()

print('No')

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, m = MAP()
a = [STR() for _ in range(n)]
b = [STR() for _ in range(m)]
for i in range(n - m + 1):
    for j in range(n - m + 1):
        flag = True
        for k in range(m):
            if a[i + k][j:j + m + 1] != b[k]:
                flag = False
                break
        if flag:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, m = MAP()
a = [STR() for _ in range(n)]
b = [STR() for _ in range(m)]
for i in range(n - m):
    for j in range(n - m):
        flag = True
        for k in range(m):
            for l in range(m):
                if a[i + k][j + l] != b[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys

def pmatch(A, B, X, Y):
    for y, Bx in enumerate(B):
        for x, b in enumerate(Bx):
            if A[Y+y][X+x] != b:
                return False
    return True

def main():
    raw = sys.stdin.readlines()
    N, M = map(int, raw[0].split())
    A = raw[1:N+1]
    B = raw[N+1:N+M+1]

    rg = range(N-M+1)

    for X in rg:
        for Y in rg:
            if pmatch(A, B, X, Y):
                return True

    return False

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

nm=N-M+1
for i in range(nm):
    for j in range(nm):
        flag=0
        for k in range(M):
            a=A[i][j:j+M]
            b=B[k]
            if a==b: flag=1
            else: flag=0
        if flag==1:
            print('Yes')
            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)]

from itertools import product
for i,j in product(range(n-m+1), repeat=2):
    t = []
    for k in range(m):
        t.append(a[k][j:j+m])

    if t == b:
        print("Yes")
        break

else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M =[int(i) for i in input().split()]

A=[]
B=[]

for i in range(N):
    A.append(str(input()))
    
for i in range(M):
    B.append(str(input()))
    
# reshape into m*m
def Reshape_m(i,j,a,m): # (the left top is (i,j))
    c=[]
    for k in range(j,j+m):
        c.append(a[k][i:i+m])
    return c
    
    
def Match_island(a,b,m):
    flag = 0
    for i in range(m):
        if a[i] ==b[i]:
            flag +=1
    if flag == m:
        return 1
    else:
        return 0
ans = "No"    
if N==M:
    if Match_island(A,B,M) ==1:
        ans = "YES" 
for p in range(N-M):
    for q in range(N-M):
        A_=Reshape_m(p,q,A,M)
        if Match_island(A_,B,M) == 1:
            ans = "Yes"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N,M =[int(i) for i in input().split()]

A=[]
B=[]

for i in range(N):
    A.append(str(input()))
    
for i in range(M):
    B.append(str(input()))
    
# reshape into m*m
def Reshape_m(i,j,a,m): # (the left top is (i,j))
    c=[]
    for k in range(j,j+m):
        c.append(a[k][i:i+m])
    return c
    
    
def Match_island(a,b,m):
    flag = 0
    for i in range(m):
        if a[i] ==b[i]:
            flag +=1
    if flag == m:
        return 1
    else:
        return 0
ans = "No"    
for p in range(N-M):
    for q in range(N-M):
        A_=Reshape_m(p,q,A,M)
        if Match_island(A_,B,M) == 1:
            ans = "Yes"
            break
print(ans)