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: Runtime Error

Solution code:
N,M=map(int,input().split())
A=[input()for i in range(N)]
B=[input()for i in range(M)]
b=''
a='no'
for i in range(M):
    b+=B[i]
for i in range(N-M+2):
    if B[0]in A[0] and B[1] in A[1]:
        for j in range(N-M+2):
            a=''
            for k in range(M):
                a+=A[i+k][j:j+M]
    if a==b:
        print("Yes")
        exit()
print("No")

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
A=[input()for i in range(N)]
B=[input()for i in range(M)]
b=''
a='no'
for i in range(M):
    b+=B[i]
for i in range(N-M+1):
    if B[0]in A[0] and B[1] in A[1]:
        for j in range(N-M+1):
            a=''
            for k in range(M):
                a+=A[i+k][j:j+M]
    if a==b:
        print("Yes")
        exit()
print("No")

Submission status: Runtime Error

Solution code:
n,m = [int(i) for i in input().split()]
a = []
for i in range(n):
	array = input()
	a.append(array)
b = []
for i in range(m):
	line = input()
	b.append(line)
ans 'No'
for i in range (n-m+1):
	for j in range(n-m+1):
		Ans = ans
		if a[i][j:j+m] == b[0]:
			print(i,j)
			for k in range(m):
				if not a[i+k][j:j+m] == b[k]:
					ans = Ans
					continue
				else:
					ans = 'Yes'
					print(ans)
					break
print(ans)

Submission status: Runtime Error

Solution code:
N,M = [int(i) for i in input().split()]
a = []
for i in range(N):
	array = input()
	a.append(array)
b = []
for i in range(M):
	line = input()
	b.append(line)
for i in range(N-M):
	for j in range(N-M):
		ans = 'Yes'
		for n in range(M):
			for m in range(M):
				if a[i+n][j+m] == b[n][m]:
					pass
					#print(i,j,n,m)
				else:
					ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
N,M = [int(i) for i in input().split()]
a = []
for i in range(N):
	array = input()
	a.append(array)
b = []
for i in range(M):
	line = input()
	b.append(line)
for i in range(N-M):
	for j in range(N-M):
		ans = 'Yes'
		for n in range(M):
			for m in range(M):
				if a[i+n][j+m] == b[n][m]:
					pass
					print(i,j,n,m)
				else:
					ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

flg1 = 1
flg2 = 0
for i in range(N):
    if flg2:
        break
    for j in range(N):
        if flg2:
            break
        flg1 = 1
        
        for k in range(M):
            if not(flg1):
                break
            for l in range(M):
                if A[i+k][j+l]==B[k][l]:
                    continue
                else:
                    flg1 = 0
        else:
            print("Yes")
            flg2 = 1
else:
    print("No")

Submission status: Runtime Error

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

for sx in range(n-1):
    for sy in range(n-1):
        chk = True
        for tx in range(m):
            for ty in range(m):
                if a[sx+tx][sy+ty] == b[tx][ty]:
                    pass
                else:
                    chk = False
                    break
        if chk:
            print('Yes')
            exit()
print('No')

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = map(int, input().split())
A = np.array([list(input()) for _ in range(N)])
B = np.array([list(input()) for _ in range(M)])
# print('AB', A, B)
for i in range(N - M + 1):
    for j in range(N - M + 1):
        # print('i j', i, j)
        A_subset = A[i:i + N - 1, j:j + N - 1]
        # print('A_subset', A_subset)
        if np.all(A_subset == B):
            print('Yes')
            exit()
print('No')

Submission status: Runtime Error

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

for i in range(n-m+1):
  for j in range(n-m+1):
    c =0
    for k in range(n-m+1):
      for l in range(n-m+1):
        if a[i+k][j+l] == b[k][l]:
          c +=1
          
      
  if c == 2*m:
    print("Yes")
    exit()
      
      
      
print("No")

Submission status: Runtime Error

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

si, sj = 0, 0


while si < m:
    ni, nj = si, sj
    rest = m ** 2
    for i in range(m):
        nj = sj
        for j in range(m):
            # print(ni, nj, i, j)
            if a[ni][nj] != b[i][j]:
                break
            nj +=1
            rest -= 1
        ni += 1
    if rest == 0:
        print("Yes")
        exit()
    sj += 1
    if sj > n - m:
        si += 1
        sj = 0

print("No")

Submission status: Runtime Error

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

for nj in range(0, n - m):
    for ni in range(0, n - m):
        for i in range(m):
            for j in range(m):
                if a[nj][ni] == b[m-1][m-1]:
                    print("Yes")
                    exit()
                if a[nj][ni] != b[j][i]:
                    break
                nj += 1
            ni += 1

print("No")

Submission status: Runtime Error

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, m = map(int, input().split())
a = [[""] * n] * n
b = [[""] * m] * m
for i in range(n):
    a[i] = [j for j in input()]
for i in range(m):
    b[i] = [j for j in input()]
# print(a)
# print(b)
for i in range(n - m):
    for j in range(n - m):
        flag = True
        for k in range(i + m):
            for l in range(j + m):
                if a[k][l] != b[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            sys.exit()
print("No")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
list = []
for i in range(H):
    list.append(input())
count = 0
for i in range(M):
    x = input()
    for j in list:
    if x in j:
        count+=1
print("No" if count=0 else "Yes")

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

L = []

for i in range(a):
    L.append([j for j in input()])

K = []

for i in range(b):
    K.append([j for j in input()])
ind = 0
for i in range(a-b+1):
    for j in range(a-b+1):
        if L[i][j] == K[0][0] and ind == 0:
            for k in range(b):
                if L[i+k][j:j+b] != K[i+k]:
                    break
                if k == b - 1 and ind == 0:
                    print("Yes")
                    ind = 1
                    break
if ind == 0:
    print("No")

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

L = []

for i in range(a):
    L.append([j for j in input()])

K = []

for i in range(b):
    K.append([j for j in input()])
ind = 0
for i in range(a-b+1):
    for j in range(a-b+1):
        if L[i][j] == K[0][0]:
            for k in range(b):
                if L[i+k][j:j+b] == K[i+k]:
                    continue
                else:
                    break
            if k == b - 1 and ind == 0:
                print("Yes")
                ind = 1
                break
if ind == 0:
    print("No")

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())

L = []

for i in range(a):
    L.append([j for j in input()])

K = []

for i in range(b):
    K.append([j for j in input()])

for i in range(a-b+1):
    for j in range(a-b+1):
        if L[i][j] == K[0][0]:
            for k in range(b):
                if L[i+k][j:j+b] == K[i+k]:
                    continue
                else:
                    break
            if k == b - 1:
                print("Yes")
                quit()
print("No")

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

AN=[]
for _ in range(N):
    AN.append(list(input()))
    
#print(AN)

AM=[]
for _ in range(M):
    AM.append(list(input()))

#print(AM)
for i in range(N-M+1):
    flag=False
    for j in range(N-M+1):
        if AN[i][j:j+M]==AM[0]:
            for k in range(i,i+M):
                if AN[k][j:j+M]!=AM[k]:
                    flag=True
                    break
            if flag:
                break
            print("Yes")
            exit()
                    

print("No")

Submission status: Runtime Error

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

if m==1:
    for i in a:
        if b[0] in i:
            print('Yes')
            exit()
        else:
            print('No')
            exit()

for i in range(n-m+1):
    cnt=0
    while cnt < n - m:
        l=[]
        for j in range(n-m+1):
        #bと同じ長さの部分配列を作る
            l+=[a[j+cnt][i:i+m]]

        if l==b:
            print('Yes')
            exit()
        cnt+=1
print('No')

Submission status: Runtime Error

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):
    for j in range(n):
        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: Runtime Error

Solution code:
def solve():
    N,M = map(int, input().split())
    A = [input() for _ in range(N)]
    B = [input() for _ in range(M)]
    idx = 0
    start_pos = {}
    for S_a in A:
        indices = set(find_indices(S_a, B[idx], N))
        if not start_pos:
            start_pos = indices
        else:
            start_pos &= indices
        
        if start_pos:
            idx += 1
        else:
            start_pos = {}
            idx = 0
            
        if idx == M:
            break
    
    print('Yes' if start_pos else 'No')
    
solve()

Submission status: Runtime Error

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

def func(base, target):
       for i in range(n-m+1):
        check = base[i:i+m]
        for j in range(n-m+1):
            check2 = [line[j:j+m] for line in check]
            if check2 == target:
                return print('Yes')
    return print('No')

func(a,b)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
A = []
for _ in range(N):
    A.append(list(input().rstrip()))
B = []
for _ in range(M):
    B.append(list(input().rstrip()))
m = len(B[0])
def search(point):
    x, y = point
    for i in range(M):
        if y > N:
            return 0
        a = A[y][x:x + m]
        if a != B[i]:
            return 0
        y += 1
    return 1
for i in range(N):
    for j in range(len(A[0])):
        if search([i, j]):
            print("Yes")
            sys.exit()
print("No")

Submission status: Runtime Error

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

flag = False

for i in range(n):
    for j in range(n-m+1):
        cnt = 0
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] == b[k][l]:
                    cnt += 1
        if cnt == m**2:
            flag = True
            break
    if flag:
        break
print("Yes" if flag else "No")

Submission status: Runtime Error

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

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


def f(i, j):
  for k in range(i, i+M):
    for l in range(j, j+M):
      if A[i+k][j+l] != B[k][l]:
        return False
  return True

def slv():
  for i in range(N-M+1):
    for j in range(N-M+1):
      if f(i, j):
        return 'Yes'
  return 'No'
print(slv())

Submission status: Runtime Error

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-m+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: Runtime Error

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+1):#各行を縦方向に比較
            if b[k] != a[i][j:j+n]:
                break
            flag = True

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

Submission status: Runtime Error

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

print(a)
print(b)

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
            flag = True

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

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
a = []
b = []
for i in range(n):
    ai = input()
    a.append(ai)
for i in range(m):
    bi = input()
    b.append(bi)
flag = True    
for i in range(n-m+1):
    flag = True
    for k in range(n-m+1):
        for j in range(i,i+m+1):
        
            if a[j][k:k+m]!=b[j-i]:
                flag = False
                break
        if flag:
            break
    if flag:
        break
#print(i,k,flag)        
print("Yes" if flag else "No")

Submission status: Runtime Error

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 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: Runtime Error

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)):
          #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: Runtime Error

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 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)):
          #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: Runtime Error

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(min(M,N)):
            #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: Runtime Error

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(0, 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: Runtime Error

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(1, M):
            #print((B[i],A[i+n][span[0][0]:span[0][1]]))
            if (B[i]==A[i+n][span[0][0]:span[0][1]]):
                allgood=True
                continue
            else:
                allgood=False
                break
        if allgood==True:
            print("Yes")
            exit()

print("No")

Submission status: Runtime Error

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

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

for i in range(N-M+1):
    for j in range(N-M+1):
        NO = False
        for x in range(M):
            a = A[i+x][j:j+M]
            if a != B[x]:
                NO = True
                break
        if not NO:
            print('Yes')
            exit()

print('No')

Submission status: Runtime Error

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

al = np.array([list(input()) for _ in range(a)])
bl = np.array([list(input()) for _ in range(b)])

flg  = False
for i in range(a - b + 1):
    for j in range(a - b + 1):
        if(al[i:i+b,j:j+b] == bl).all():
            flg = True
            
print('Yes' if flg else 'No')

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

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

hidariue = b[0][0]
hasikouho = []
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j] == hidariue:
            hasikouho.append(str(i)+":"+str(j))

x = []

for v in hasikouho:
    ans = "Yes"
    i = int(v[0])
    j = int(v[2])
    for p in range(m):
        if ans == "Yes":
            for q in range(m):
                if a[i+p][j+q] != b[p][q]:
                    ans = "No"
                    break
        else:
            break
    x.append(ans)

if "Yes" in x:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
print(A)
# 全探索で間に合う？
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: Runtime Error

Solution code:
N,M = map(int,input())
A = [input() for _ in range(N)]
B = [input() for _ in range(N)]
ans = 0
for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(i,i+M):
      for l in range(j,j+M):
        if A[k][l] != B[k][l]:
          break
        if A[k][l] == B[k][l] and k == i+M-1 and l == j+M-1:
          ans = 1
    else:
      continue
    break
if ans == 0:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

bool solve() {
    ll N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    for ( int i = 0; i < M; i++ ) {
        cin >> B[i];
    }

    for ( int i1 = 0; i1 + M < N; i1++ ) {
        for ( int i2 = 0; i2 + M < N; i2++ ) {
            bool ng = false;
            for ( int j1 = 0; j1 < M; j1++ ) {
                if ( A[i1+j1].substr(i2, M) != B[j1] ) {
                    ng = true;
                    break;
                }
            }
            if ( !ng ) return true;
        }
    }
    return false;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

A=np.asarray(A)
B=np.asarray(B)
flg=False

  
for x in range(N-M):
    for y in range(N-M):
        if (A[x:x+M,y:y+M] == B).all():
            flg=True
if flg:
    print("Yes")
else:
    if (A == B).all():
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

A=np.asarray(A)
B=np.asarray(B)
flg=False
if (A == B).all():
    flg=True
  
for x in range(N-M):
    for y in range(N-M):
        if (A[x:x+M,y:y+M] == B).all():
            flg=True
if flg:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
m,n =map(int,input().split())
a=[input() for _ in range(m)]
b=[input() for _ in range(m)]
r=any([r[j:j+m] for r in a[i:i+m]]==b for i in range (n-m+1) for j in range(n-m+1))
print("Yes" if r else "No")

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def is_match(parent, child, pi, pj):
    for ci in range(len(child)):
        for cj in range(len(child[ci])):
            # c = child[ci][cj]
            # p = parent[pi+ci][pj+cj]
            if child[ci][cj] != parent[pi+ci][pj+cj]:
                return False
    return True


def solve(N, M, inputs):
    map_parent = list(map(list, inputs[:N]))
    map_child = list(map(list, inputs[N:]))

    for pi in range(0, M):
        for pj in range(0, M):
            if is_match(map_parent, map_child, pi, pj):
                return 'Yes'
    return 'No'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(N+M))
    print(ret)

Submission status: Runtime Error

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

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

b_index = 0
for i in range(N):
    for j in range(len(A[i])):
        if A[i][j] == B[0][0]:
            for i2 in range(M):
                for j2 in range(len(B[i2])):
                    if A[i+i2][j+j2] != B[i2][j2]:
                        break
                else:
                    continue
                break
            else:
                print('Yes')
                exit()
print('No')

Submission status: Runtime Error

Solution code:
n , m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
#i, j はBの左端
for i in range(n-m):
    ans = True
    for j in range(n-m):
        for k in range(m):
            if a[i + k][j:j+m] != b[k]:
                ans = False
        if ans == True:
            break
    else:
        continue
    break

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

Submission status: Runtime Error

Solution code:
N,M = int(input())
A = []
B = []
for i in range(N):
    A.append(input())
for i in range(M):
    B.append(input())
for i in range(N-M+1):
    for k in range(N-M+1):
        p = 1
        for j in range(i,i+M):
            a = A[j][k:k+M]
            b = B[j-i][k+M]
            if a != b:
                p = 0
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
4 1
....
....
....
....
#

Submission status: Runtime Error

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

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

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

is_contained = 'No'

for i in range(n - m + 1):
    for j in range(m - i):
        if b[j] in a[j]:
            if a[j].index(b[j]) != a[i].index(b[i]):
                break
    else:
        is_contained = 'Yes'
        break

print(is_contained)

Submission status: Runtime Error

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

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

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

is_contained = 'No'

for i in range(n - m + 1):
    if b[0] in a[i]:
        for j in range(m - i):
            if a[j].index(b[j]) != a[i].index(b[i]):
                break
        else:
            is_contained = 'Yes'
            break

print(is_contained)

Submission status: Runtime Error

Solution code:
n, m = [int(x) for x in input().split()]
img_a = [input() for _ in range(n)]
img_b = [input() for _ in range(m)]

found = False
for a in range(n - m + 1):
    border = 0
    isok = True
    while isok and not flag:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                isok = False
                break

        else: # if not loop broken.
            ans = "Yes"
            found = True
            break
    if found:
        break
else: # if not 'found==True' even after last loop, then it means B is not in A.
    ans = "No"
        
print(ans)

Submission status: Runtime Error

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

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

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

ans = "No"
for a in range(n - m + 1):
    dup_a = img_a.copy()
    dup_b = img_b.copy()
    flag = True
    while flag:
        for b in range(m):
            if dup_b[b] in dup_a[b+a]:
                if b == 0:
                    index = dup_a[a].index(dup_b[0])
                current_index = dup_a[b+a].index(dup_b[b])
                if current_index != index:                
                    if current_index > index:
                        for line in dup_a:
                            del line[:current_index]
                        break
                    else:
                        for line in dup_a:
                            del line[:index]
                        break
            else:   # if not substring in string.
                flag = False
                break

        else: # if not for loop broken.
            ans = "Yes"
            break
        

print(ans)