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 = [input() for _ in range(N)]
B = [input() for _ in range(M)]

exist = False
for i in range(N-M+1):
    for j in range(N-M+1):
        match = True
        for k in range(M):
            for l in range(M):
                if A[i][j] != B[k][l]:
                    match = False
        if match:
            exist = True

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

Submission status: Wrong Answer

Solution code:
[n,m]=list(map(int,input().split()))
alist=[]
blist=[]
counter=0
for i in range(n):
    alist.append(list(input()))
for i in range(m):
    blist.append(list(input()))
clist=[]
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            kari=[]
            for l in range(m):
                kari.append(alist[i+k][j+l])
            clist.append(kari)
        
        if blist==clist:
            counter=1
            break
        clist=[]

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

Submission status: Wrong Answer

Solution code:
[n,m]=list(map(int,input().split()))
alist=[]
blist=[]
counter=0
for i in range(n):
    alist.append(list(input()))
for i in range(m):
    blist.append(list(input()))
clist=[]
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            kari=[]
            for l in range(m):
                kari.append(alist[i+k][j+l])
            clist.append(kari)
        
        if blist==clist:
            counter=1
            break

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

Submission status: Wrong Answer

Solution code:
[n,m]=list(map(int,input().split()))
alist=[]
blist=[]
counter=0
for i in range(n):
    alist.append(list(input()))
for i in range(m):
    blist.append(list(input()))
clist=[]
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            kari=[]
            for l in range(m):
                kari.append(alist[i][j+l])
            clist.append(kari)
        
        if blist==clist:
            counter=1
            break

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

Submission status: Wrong Answer

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

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

bList = []
for j in range(m):
  bList.append(input())

for k in range(n-(m-1)):
  aIMatch = aList[k].find(bList[0])
  if aIMatch >= 0:
    sucFlag = True 
    for l in range(1,m):
      aNMatch = aList[k+l].find(bList[l])
      if not(aNMatch >= 0 and aIMatch == aNMatch):
        sucFlag = False
        break
    if sucFlag:
      print("Yes")
      exit(0)

print("No")

Submission status: Wrong Answer

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

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

bList = []
for j in range(m):
  bList.append(input())

for k in range(n-(m-1)):
  aIMatch = aList[k].find(bList[0])
  if aIMatch > 0:
    sucFlag = True 
    #mの長さが1ならマッチングは既に終了。そうでなければマッチング継続。 
    if m > 1:
        for l in range(1,m):
          aNMatch = aList[k+l].find(bList[l])
          if not(aNMatch > 0 and aIMatch == aNMatch):
            sucFlag = False
            break
    if sucFlag:
      print("Yes")
      exit(0)

print("No")

Submission status: Wrong Answer

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

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

bList = []
for j in range(m):
  bList.append(input())

for k in range(n-(m-1)):
  aIMatch = aList[k].find(bList[0])
  if aIMatch > 0:
    sucFlag = True 
    for l in range(1,m):
      aNMatch = aList[k+l].find(bList[l])
      if not(aNMatch > 0 and aIMatch == aNMatch):
        sucFlag = False
        break
    if sucFlag:
      print("Yes")
      exit(0)

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

k=N-M+1
ans=False

for i in range(k):
    for j in range(k):
        flg=True
        
        for p in range(M):
            for q in range(M):
                if A[i+p][j+q] != B[p][q]:
                    flg=False
        
        ans=flg
        
        if ans:
            break

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

check = 0
k = 0
l = 0
for i in range(n):
   for j in range(n):
      if (b[k][l] == a[i][j]):
         check = 1
         l += 1
      if (check == 1 and l == m):
         l = 0
         k += 1
         break

   if (k == m):
      if (check == 1):
         print('Yes')
         exit()
      else:
         k = 0
         l = 0

print('No')

Submission status: Wrong Answer

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

for i in range(m):
  b.append([i for i in input()])
  
for i in range(n-m+1):
  flg=True
  if b_flg:
    break
  for j in range(n-m+1):
    if not flg:
      break
    for k in range(m):
      if not flg:
        break
      for l in range(m):
        if a[i+k][j+l]==b[k][l]:
          flg=True
        else:
          flg=False
    if flg:
      b_flg=True
      break
if b_flg:
  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)]

ans = None
for i in range(N-M+1):
  for j in range(N-M+1):
    try:
      for k in range(i, i+M):
        for l in range(j, j+M):
          if A[i+k][j+l] != B[k][l]:
            raise ""
      else:
        ans = 'Yes'
    except:
      pass

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

ans = None
for i in range(N-M):
  for j in range(N-M):
    try:
      for k in range(i, i+M):
        for l in range(j, j+M):
          if A[i+k][j+l] != B[k][l]:
            raise ""
      else:
        ans = 'Yes'
    except:
      pass

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

for i in range(N-M):
  for j in range(N-M):
    try:
      for k in range(i, i+M):
        for l in range(l, l+M):
          if A[i+k][j+k] != B[k][l]:
            raise ""
      else:
        print('Yes')
    except:
      print('No')

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
a = [str(input()) for _ in range(n)]
b = [str(input()) for _ in range(m)]
flag = False
for k in range(n-n+1):
    cnt = 0
    for i in range(m):
        for j in range(m):
            if b[k+i][j]==a[k+i][j]:
                cnt += 1
        if cnt==m**2:
            flag = True
            break
    if flag:
        break
print('Yes' if flag else 'No')

Submission status: Wrong Answer

Solution code:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を1行ずつ比較
            if b[k] != a[i+k][j:j+n+1]:
                break
        else:
            flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を1行ずつ比較
            if b[k] != a[i][j:j+n]:
                break
        else:
            flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を横方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())
flag = False
for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を横方向に比較
            print(k,j,i)
            if b[k] != a[i][j:j+n]:
                break
            flag = True
if flag:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

for i in range(m-n+1):#比較開始を縦方向に動かす
    for j in range(m-n+1):#比較開始を横方向へ動かす
        for k in range(n):#各行を縦方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True

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

Submission status: Wrong Answer

Solution code:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

for i in range(0, m-n):#比較開始を縦方向に動かす
    for j in range(0, m-n):#比較開始を横方向へ動かす
        for k in range(0,n):
            if b[k] != a[i][j:j+n]:
                break
            flag = True

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

Submission status: Wrong Answer

Solution code:
m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

for i in range(0, m-n):#比較開始を縦方向に動かす
    for j in range(0, m-n):#比較開始を横方向へ動かす
        for k in range(0,n):
            if b[k] != a[i][j:j+n]:
                break
        else:
            flag = True

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

Submission status: Wrong Answer

Solution code:

m,n = map(int,input().split())
a = []*m
b = []*n
flag = False
for i in range(m):
    a.append(input())
for j in range(n):
    b.append(input())

for i in range(0, m-n):#比較開始を縦方向に動かす
    for j in range(0, m-n):#比較開始を横方向へ動かす
        for k in range(0,n):
            if b[k] != a[k][j:j+n]:
                break
        else:
            flag = True

if flag:
    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):
    for j in range(n-m):
        ans = 0
        for ii in range(m):
            for jj in range(m):
                if b[ii][jj] == a[i+ii][j+jj]:
                    ans += 1
        if ans == m*m:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
a=[]
for i in range(N):
  a.append([i for i in input()])
b=[]
for i in range(M):
  b.append([i for i in input()]) 
flg=True
for iS in range(0,N-M+1):
  for ie in range(iS,M):
    flg=True 
    for js in range(0,N-M+1):
      for je in range(js,M):
        if a[ie][je]!=b[ie][je]:
          flg=False
          break
print("Yes" if flg else "No")

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
a=[]
for i in range(N):
  a.append([i for i in input()])
b=[]
for i in range(M):
  b.append([i for i in input()]) 
flg=True
for iS in range(0,N-M+1):
  for ie in range(iS,M):
    flg=True 
    for js in range(0,N-M+1):
      for je in range(js,M):
        print(a[ie][je],b[ie][je])
        if a[ie][je]!=b[ie][je]:
          flg=False
          break
print(flg)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N, M = map(int, input().split())
A, B = [], []
for i in range(N):
    tmp = input()
    A.append(tmp[:])
for i in range(M):
    tmp = input()
    B.append(tmp[:])
for r in range(len(A[0]) - len(B[0]) + 1):
    for i in range(N - M + 1):
        cnt = 0
        for j in range(i, M+i):
            # print(A[j][r:r+len(B[0])], B[j-i])
            if A[j][r:r+len(B[0])+1] == B[j-i]:
                cnt += 1
        if cnt == M:
            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)]
flag=True
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]:
                    flag=False
                    break
            if not flag:
                break
        if flag:
            print('Yes')
            break

if not flag:
    print('No')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

ans = False
for i in range(N):
    for j in range(M):
        if i + M - 1 >= N or j + M - 1 >= N:
            continue
        match = True
        for y in range(M):
            for x in range(M):
                if A[i + y][j + x] != B[y][x]:
                    match = False
        if match:
            ans = True

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

Submission status: Wrong Answer

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

A=[]
B=[]

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

for m in range(M):
    B.append(input())
        
if N<M:
    print("No")
    exit()
# check
for n in range(N):
      # Bのm行目と一致
      # Bのm+1行目と一致するかチェック
      span =[m.span() for m in re.finditer(B[0], A[n])]
      #print(span)
      if span==[]:
          continue
      allgood=False
      for i in range(min(M,N)):
          if n+i>=N:
              allgood=False
              break
          #print(n)
          #print((B[i],A[n+i][span[0][0]:span[0][1]]))
          if (B[i]==A[n+i][span[0][0]:span[0][1]]):
              allgood=True
              continue
          else:
              allgood=False
              break
      if allgood==True:
          print("Yes")
          exit()

print("No")

Submission status: Wrong Answer

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

A=[]
B=[]

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

for m in range(M):
    B.append(input())
        
# check
for m in range(M):
    for n in range(N):
        # Bのm行目と一致
        # Bのm+1行目と一致するかチェック
        span =[m.span() for m in re.finditer(B[m], A[n])]
        #print(span)
        if span==[]:
            continue
        allgood=False
        # フィルタが1行ならYesを返す
        if M==1:
            print("Yes")
            exit()
        for i in range(n+1, M):
            #print((B[i],A[i][span[0][0]:span[0][1]]))
            if (B[i]==A[n+i][span[0][0]:span[0][1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

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

A=[]
B=[]

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

for m in range(M):
    B.append(input())
        
# check
for m in range(M):
    for n in range(N):
        # Bのm行目と一致
        # Bのm+1行目と一致するかチェック
        span =[m.span() for m in re.finditer(B[m], A[n])]
        #print(span)
        if span==[]:
            continue
        allgood=False
        # フィルタが1行ならYesを返す
        if M==1:
            print("Yes")
            exit()
        for i in range(n+1, M):
            #print((B[i],A[i][span[0][0]:span[0][1]]))
            if (B[i]==A[i][span[0][0]:span[0][1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

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

A=[]
B=[]

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

for m in range(M):
    B.append(input())
        
# check
for m in range(M):
    for n in range(N):
        # Bのm行目と一致
        # Bのm+1行目と一致するかチェック
        span =[m.span() for m in re.finditer(B[m], A[n])]
        print(span)
        if span==[]:
            continue
        allgood=False
        # フィルタが1行ならYesを返す
        if M==1:
            print("Yes")
            exit()
        for i in range(n+1, M):
            print((B[i],A[i][span[0][0]:span[0][1]]))
            if (B[i]==A[i][span[0][0]:span[0][1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

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

A=[]
B=[]

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

for m in range(M):
    B.append(input())
        
# check
for m in range(M):
    for n in range(N):
        # Bのm行目と一致
        # Bのm+1行目と一致するかチェック
        span =[m.span() for m in re.finditer(B[m], A[n])]
        #print(span)
        if span==[]:
            continue
        allgood=False
        # フィルタが1行ならYesを返す
        if M==1:
            print("Yes")
            exit()
        for i in range(n+1, M):
            #print((B[i][span[0][0]:span[0][1]],A[i][span[0][0]:span[0][1]]))
            if (B[i][span[0][0]:span[0][1]]==A[i][span[0][0]:span[0][1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

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

A=[]
B=[]

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

for m in range(M):
    B.append(input())
        
# check
for m in range(M):
    for n in range(N):
        # Bのm行目と一致
        # Bのm+1行目と一致するかチェック
        span =[m.span() for m in re.finditer(B[m], A[n])]
        #print(span)
        if span==[]:
            continue
        allgood=False
        for i in range(n+1, M):
            #print((B[i][span[0][0]:span[0][1]],A[i][span[0][0]:span[0][1]]))
            if (B[i][span[0][0]:span[0][1]]==A[i][span[0][0]:span[0][1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            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)]


for i in range(N - M):
        for j in range(N - M):
                flag = True
                for h in range(M):
                        for w in range(M):
                                if A[i+h][j+w] != B[h][w]:
                                        flag = False             
                                        break
                if flag == True:
                        print("Yes")
                        exit()
print("No")

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
la=[]
lb=[]
for i in range(N):
    la.append(input())
for i in range(M):
    lb.append(input())
f=0
for i in range(N-M):
    if f==1:
        break
    for j in range(N-M):
        if f==1:
            break
        f=0
        for k in range(M):
            if f==-1:
                break
            for l in range(M):
                if la[i+k][j+l]!=lb[k][l]:
                    f=-1
                    break
            if k==M-1 and l==M-1 and f!=-1:
                f=1
                break

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

Submission status: Wrong Answer

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


N,M=map(int,input().split())
A = []
B = []

for i in range(N):
	A.append(list(map(lambda x:1 if x=='#' else 0, input())))

for i in range(M):
	B.append(list(map(lambda x:1 if x=='#' else 0, input())))


f=False
for i in range(N-M+1):
	for j in range(N-M+1):
		f=func(i,j)

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

Submission status: Wrong Answer

Solution code:
S=input()
ans=0
cnt=0
flg=False
for s in S:
    if s=="A":
        cnt+=1
        flg=True
        continue
    if s=="Z" and flg:
        cnt+=1
        flg=False
        ans=max(ans,cnt)
        cnt=0
        continue
    cnt+=1
print(ans)

Submission status: Wrong Answer

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

A = []
for i in range(N):
    tmp = input()
    A.append([0 if s=="." else 1 for s in tmp])
B = []
for i in range(M):
    tmp = input()
    B.append([0 if s=="." else 1 for s in tmp])
    
A = np.array(A)
B = np.array(B)

def is_match(a, b):
    return (a==b).all()
flag = False
for i in range(N):
    for j in range(N):
        x_left = i
        x_right = i + M
        y_up = j
        y_under = j + M
        if x_right >= N or y_under >= N:
            continue
        if is_match(B, A[x_left:x_right, y_up:y_under]):
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

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

flag = False

print(a)
print(b)

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

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

Submission status: Wrong Answer

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

class Image:
    def __init__(self, n):
        self.matrix = [list(input()) for _ in range(n)]
        self.n = n

    def isIncluded(self, a):
        for i in range(a.n):
            for j in range(a.n):
                if a.matrix[i][j] == self.matrix[0][0]:
                    if j+self.n <= a.n and i+self.n <= a.n:
                        template = [a.matrix[i+k][j:j+self.n]
                                    for k in range(self.n)]
                        print(template)
                        if template == self.matrix:
                            return True
        return False


a = Image(n)
b = Image(m)

print("Yes" if b.isIncluded(a) else "No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

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 k in range(m):
            # print(i,j,k)
            if A[i+k][j:j+m] != B[k][j:j+m]:
                break
        else:
            print("Yes")
            exit()
        # print(i,j)
        continue
print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

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 k in range(m):
            # print(i,j,k)
            if A[i+k][j:j+m] != B[k][j:j+m]:
                break
        else:
            print("Yes")
            exit()
        # print(i,j)
        continue
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 i in range(m)]
for i in range(n-m+1):
  flag = 0
  for j in range(m):
    for k in range(m):
      if b[j][k] != a[i+j][i+k]:
        flag = 1
        break
    if flag == 1:
      break
  if flag == 0:
    print("Yes")
    break
if flag == 1:
  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 i in range(m)]
flag = 0
for i in range(n-m+1):
  flag = 0
  for j in range(m):
    for k in range(m):
      if b[j][k] != a[i+j][i+k]:
        flag = 1
        break
  if flag == 0:
    print("Yes")
    break
if flag == 1:
  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()))
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if a[i][j:j+m]!=b[k]:
                continue
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
a = [[j for j in input()] for i in range(n)]
b = [[j for j in input()] for i in range(m)]
ans = 'No'
na = np.array(a)
nb = np.array(b)
for i in range(n-m):
    for j in range(n-m):
        s = na[i:m+i, range(j, m+j)]
        if (s == nb).all():
            ans = 'Yes'
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
a = [[j for j in input()] for i in range(n)]
b = [[j for j in input()] for i in range(m)]
ans = 'No'
na = np.array(a)
nb = np.array(b)
for i in range(n-m):
    s = na[i:m+i, range(i, m+i)]
    if (s == nb).all():
        ans = 'Yes'
        break
print(ans)

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

f = True
for i in range(n - m + 1):
    for j in range(n - m + 1):
        #check
        for x in range(m):
            for y in range(m):
                if a[x + i][y + j] != b[x][y]:
                    f = False

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

for i in range(n - m + 1):
    for j in range(n - m + 1):
        #check
        f = True
        for x in range(m):
            for y in range(m):
                if a[x + i][y + j] != b[x][y]:
                    f = False

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

Submission status: Wrong Answer

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

for a in range(N - M + 1):
    l = [x[a : a + M] for x in lst_n[a : a + M]]
    if l == lst_m:
        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)]
ans = "No"
for i in range(n - m + 1):
  for j in range(n - m + 1):
    S = []
    for k in range(m):
      if m == 1:
        S.append(A[i + k][j])
      else:
        S.append(A[i + k][j:m])
      if S == B:
        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)]
ans = "No"
for i in range(n - m + 1):
  for j in range(n - m + 1):
    S = []
    for k in range(m):
      #print(k)
      #print(A[0][0:0])
      if m == 1:
        S.append(A[i + k][0])
      else:
        S.append(A[i + k][j:m])
      #print(f"Sis{S}")
      if S == B:
        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)]
ans = "No"
for i in range(n - m + 1):
  for j in range(n - m + 1):
    S = []
    for k in range(m):
      S.append(A[i + k][j:m])
      if S == B:
        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)]

ans = "No"
flag = False

for i in range(n-m):
    for j in range(n-m):
        if b[0][0] == a[i][j]:
            atmp = []
            atmp.extend([a[s][j:j+m] for s in range(i,i+m)])
            if b == atmp:
                ans = "Yes"
                flag = True
        if flag:
            break
    if flag:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
nn=""
mm=[]
for i in range(n):
    nn+=input()+"\n"
for i in range(m):
    mm.append(input())
count=0
for i in range(m):
    if(mm[i] in nn ):
        count+=1

if(count==m):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
N,M=map(int,input().split())
A=np.zeros((N,N))
B=np.zeros((M,M))
for i in range(N):
    temp=input()
    temp=temp.replace('.',"0")
    temp=temp.replace('#',"1")
    A[i] = list(map(int,list(temp)))
for i in range(M):
    temp=input()
    temp=temp.replace('.',"0")
    temp=temp.replace('#',"1")
    B[i] = list(map(int,list(temp)))

for i in range(N-M+1):
    for j in range(N-M+1):
        if np.any(B == A[i:i+M,j:j+M]):
            print("Yes")
            sys.exit()
else:
    print("No")

Submission status: Wrong Answer

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

import sys

flag=False

for k in range(N):
    if B[0] in A[k] and N-k>=M:
        tmp=k
        start=A[k].find(B[0])
        flag=True
        break

if flag==False:
    print('No')
    sys.exit()

if M==1:
    print('Yes')
    sys.exit()

for l in range(1,M):
    if A[tmp+l].find(B[l])==start:
        continue
    else:
        flag=False
        break

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

Submission status: Wrong Answer

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

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

ans = "Yes"
for a in A:
    for b in B:
        print(a, b)
        if b not in a:
            ans = "No"
print(ans)