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 = [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:
                    continue
                elif 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 loop broken.
            ans = "Yes"
            break
        

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()
    while True:
        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:
                    continue
                elif 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.
                break
        
        if not dup_b[b] in dup_a[b+a]:
            break

        # if not loop broken.
        ans = "Yes"
        break
        

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()
    while True:
        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:
                    for line in dup_a:
                        del line[:current_index]
                        break
                elif current_index < index:
                    for line in dup_a:
                        del line[:index]
                        break
        
            else:   # if not substring in string.
                break
        else: # if not loop broken.
            ans = "Yes"
            break
        if not dup_b[b] in dup_a[b+a]:
            break

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()
    while True:
        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:
                    for line in dup_a:
                        del line[:current_index]
                        break
                elif current_index < index:
                    for line in dup_a:
                        del line[:index]
                        break
        
            else:   # if not substring in string.
                break
        else: # if not loop broken.
            ans = "Yes"
            break
        if not dup_b[b] in dup_a:
            break

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()
    while True:
        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:
                    for line in dup_a:
                        del line[:current_index]
                        break
                elif current_index < index:
                    for line in dup_a:
                        del line[:index]
                        break
        
            else:   # if not substring in string.
                break
        else: # if not loop broken.
            ans = "Yes"
            break

print(ans)

Submission status: Runtime Error

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

for i in range(N-M+1):
    for j in range(N-M+1):
        new = [A[k][j:j+M] for k in range(i,i+M)]
        if new == b:
            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)]

tmp = []
for k in range(n):
    for i in range(n):
        if i+m <= n:
            for j in range(m):
                tmp.append(a[k+j][i:i+m])
        if tmp == b:
            print('Yes')
            exit()
        tmp = []
else:
    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-M+1):
  for _ in range(A[i].count(B[0])):
    l = A[i].index(B[0], l)
    result = True
    for k in range(1, M):
      if B[k] != A[i+k][l:l+len(B[k])]:
        result = False
        break
    if result:
      print("Yes")
      exit()
    l += 1
      
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)]

ans = 'No'
for i in range(N):
    if A[i].find(B[0]) > -1:
        x = A[i].find(B[0])
        y = i + 1
        ans = 'Yes'
        break
for j in range(1, M):
    if B[j] != A[y][x:M]:
        ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
import io
sys.stdin = io.StringIO("""3 2
#.#
.#.
#.#
#.
.#
""")
import sys
def main():
    t = sys.stdin.readline()
    t1 = t.rstrip()
    t2 = t1.split(' ')
    stra = [] 
    for i in range(int(t2[0])):
        y = sys.stdin.readline()
        t = y.rstrip()
        stra += [t]
    strb = [] 
    for i in range(int(t2[1])):
        y = sys.stdin.readline()
        t = y.rstrip()
        strb += [t]

    suma = 0
    for x in strb:
        for y in stra:
            print(x,y)
            if x in y:
                suma +=1 
    if int(t2[0])*int(t2[1])==suma:
        print("yes")
    
    print(stra,strb)
main()

Submission status: Runtime Error

Solution code:
first=input()
(N, M)=first.split()
N=int(N)
M=int(M)
for A in range(N):
    input()
    int(A)
for B in range(5-N):
    input()
    int(B)
if B in A:
    print("Yes")
else:
    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)]
flg = 0
for dx in range(N-M):
    for dy in range(N-M):
#        print(A[dy][dx:N-1-dx],B[dy])
        if all(A[i+dy][dx:N-1-dx]==B[i+dy] for i in range(M)):
            flg =1
if flg == 1: print("Yes")
else: 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-M+1):
    for j in range(N-M+1):
        cnt = 0
        for k in range(i,i+M): # yoko
            for l in range(j,j+M): # tate
                if A[k][l]!=B[k][l]:
                    break
                else:
                    cnt+=1
        if cnt == M*M:
            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)]

flag = 'No'
for i in range(N-M):
    for j in range(N-M):
        check = []
        for k in range(M):
            if A[i+k][j:j+M] == B[i+k]:
                check.append(1)
            else:
                check.append(-1)
        if sum(check) == M:
            flag = 'Yes'
print(flag)

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

Submission status: Runtime Error

Solution code:
h, w = map(int,(input().split()))

a=[]
b=[]

for i in range(h):
    a.append(input())
for i in range(w):
    b.append(input())
ans='No'

for i in range(h):
    if a[i].find(b[0]) >0:
        l= a[i].find(b[0])
        for k in range(1,w):
            print(a[i+k][l:len(b[0])+1])
            print(b[k])
            if a[i+k][l:len(b[0])+1]==b[k]:
                ans='Yes'
            else:
                ans='No'

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = []
b = []
fl = False
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):
    if b[0] in a[i]:
        tmp = a[i].find(b[0])
        if m == 1:
            fl = True
        for j in range(1,m):
            if a[i+j][tmp:tmp+m] != b[j]:
                fl = False
                break
            fl = True
    if fl:
        break
        if fl:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
def main():
    n, m = (int(i) for i in input().split())
    a = [input() for i in range(n)]
    b = [input() for i in range(m)]
    
    equal_flag = False
    k = 0
    for i in range(n):
        for j in range(n-m+1):
            if a[i][j:j+m] == b[k]:
                plus = 1
                while k+plus != m:
                    if a[i+plus][j:j+m] != b[k+plus]:
                        break
                    plus += 1
                else:
                    equal_flag = True
        if equal_flag:
            print("Yes")
            break
    else:
        print("No")

if __name__ == '__main__':
    main()

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 - M + 1):
  for j in range(N - M + 1):
    ok = True
    if A[i + j][j:j + M] != B[k]:
      ok = False
      break
    if ok:
      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)]

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

Submission status: Runtime Error

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

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

#貪欲にやれドアホ
for i in range(n-m):
    for j in range(n-m):
        c=0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                c+=1
            else:
                break
        if c==m:
            break
    if c==m:
        break
if c==m or (n==m and a==b):
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

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

#貪欲にやれドアホ
for i in range(n-m):
    for j in range(n-m):
        c=0
        for k in range(m):
            if b[k] == a[i+k][j:j+m]:
                c+=1
            else:
                break
        if c==m:
            break
    if c==m:
        break
if c==m:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import sys
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
count = 0
idx = 0
position = []
for b in B:
    if idx == 0:
        for i, a in enumerate(A[:-m]):
            if b in a:
                position.append(a.find(b))
                if a.count(b) > 1:
                    position.append(a.rfind())
                    position.append(a.find(b, a.find(b)))
                count += 1
                idx = i
                break
        if count == 0:
            print('No')
            sys.exit()
    else:
        for i, a in enumerate(A[idx+1:]):
            for p in position:
                if b == a[p:p + m]:
                    break
                print('No')
                sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import sys
n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
count = 0
idx = 0
position = []
for b in B:
    if idx == 0:
        for i, a in enumerate(A[:-m]):
            if b in a:
                position.append(a.find(b))
                if a.count(b) > 1:
                    position.append(a.rfind())
                count += 1
                idx = i
                break
        if count == 0:
            print('No')
            sys.exit()
    else:
        for i, a in enumerate(A[idx+1:-m]):
            for p in position:
                if b == a[p:p + m]:
                    break
                print('No')
                sys.exit()
print('Yes')

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,M = inputMap()
    A = []
    for i in range(N):
        tmp = input()
        A.append(tmp)
        
    B = []
    for i in range(M):
        tmp = input()
        B.append(tmp)
        
    if N < M:
        print("No")
        sys.exit()
        
    if N == M:
        tmp1 = "".join(A)
        tmp2 = "".join(B)
        
        if tmp1 == tmp2:
            print("Yes")
        else:
            print("No")
        sys,exit()
        
    points = []
    AA = copy.deepcopy(A)
    for i,val in enumerate(AA):
        while True:
            tmp = run(val, B[0])
            if tmp != -1:
                points.append((i,tmp))
                valval = list(copy.deepcopy(val))
                valval[tmp] = "T"
                val = "".join(valval)
            else:
                break
            
    for i in points:
        lines, point = i
        flg = True
        for j,val in enumerate(B):
            tmp = A[lines+j].find(val)
            if tmp == -1:
                flg = False
        
        if flg == True:
            print("Yes")
            sys.exit()
            
    print("No")
    
def run(ss, dd):
    return ss.find(dd)
    
if __name__ == "__main__":
	main()

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

ans = "No"
for x in range(0,n-m):
    for y in range(0,n-m):
        bina = True
        for i in range(m):
            for j in range(m):
                if a[i][j] != b[x+i][y+j]:
                    bina = False
        if bina:
            ans = "Yes"

print(ans)

Submission status: Runtime Error

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

A = [None]*N
for i in range(N):
    A[i] = input()

B = [None]*M
for i in range(M):
    B[i] = input()

def check():
    for x in range(N-M+1):
        for y in range(N-M+1):
            if all(all(A[r+x][c+y] == B[r][c] for c in range(M)) for r range(M))
                return "Yes"
    return "No"
print(check())

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(m):
  for j in range(m):
    if a[i][j] == b[i][j]:
      pass
    else:
      a = []
if a == []:
  print('No')
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
def main():
    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):
            f = True
            for k in range(M):
                for l in range(M):
                    if A[i + k][j + l] != B[k][l]:
                        f = False
                        break
                if f is False:
                    break
            if f is True:
                print('Yes')
                exit()
    print('No')


main()

Submission status: Runtime Error

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

a_list_list = []

for i in range(0, n):
    a_list_list.append(input().split()[0])

b_list_list = []

for i in range(0, m):
    b_list_list.append(input().split()[0])

def is_match(source_list_list, b_list_list, source_start_x):

    for k in range(len(b_list_list)):
        for l in range(len(b_list_list[0])):
            if source_list_list[k][source_start_x + l] != b_list_list[k][l]:
                return False

    return True

# def debug_print(source):
#     print('==============')
#     for row in source:
#         print(row)
#     print('==============')

is_ok = False

# debug_print(b_list_list)

for j, _ in enumerate(a_list_list):
    target_a_list_list = a_list_list[j:j+m]
    for i in range(0, n-m):
        # debug_print(target_a_list_list)
        if is_match(target_a_list_list, b_list_list, i):
            is_ok = True
            break
    if is_ok:
        break

ans = 'Yes' if is_ok else 'No'

print(ans)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
  a.append(input())
for j in range(m):
  b.append(input())n,m=map(int,input().split())
a=[]
b=[]
l=0
k=0
temp=[]
res=False
for i in range(n):
  a.append(input())
for j in range(m):
  b.append(input())
#print(a)
while k<=n-m+1:
  while l+m<=n:
    for o in range(m):
      temp.append(a[o+k][l:l+m])
      print(o,m,k)
    l+=1
    print(temp)
    temp=[]
  k+=1

Submission status: Runtime Error

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

a = []
for x in range(0, N):
  a.append(input())

b = []
for x in range(0, M):
  b.append(input())

for i in range(0, len(a)):
  found = a[i].find(b[0])
  if found != -1:
    tmp = []
    for j in range(i, len(b)+1):
      tmp.append(a[j][found:found+M])
    if "".join(tmp) ==  "".join(b):
      print("Yes")
      exit()
  
print("No")

Submission status: Runtime Error

Solution code:
import numpy as np
n,m = list(map(int, input().split()))
tmp_a = [list(input()) for _ in range(n)]
tmp_b = [list(input()) for _ in range(m)]

a = np.array(tmp_a)
b = np.array(tmp_b)

for a_i in range(n - m + 1):
    for a_j in range(n - m + 1):
        if((a[a_i:a_i + m, a_j:a_j + m] == b).all()):
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

Solution code:
import numpy as np
n,m = list(map(int, input().split()))
tmp_a = [list(input()) for _ in range(n)]
tmp_b = [list(input()) for _ in range(m)]

a = np.array(tmp_a)
b = np.array(tmp_b)

for a_i in range(n - m + 1):
    for a_j in range(n - m + 1):
        if((a[a_i:a_i + m, a_j:a_j + m] == b).all()):
          print("Yes")
          exit()
print("No")

Submission status: Runtime Error

Solution code:
import numpy as np
n,m = list(map(int, input().split()))
tmp_a = [list(input()) for _ in range(n)]
tmp_b = [list(input()) for _ in range(m)]

a = np.array(tmp_a)
b = np.array(tmp_b)

for a_i in range(n - m + 1):
  for a_j in range(n - m + 1):
      if((a[a_i:a_i + m, a_j:a_j + m] == b).all()):
        print("Yes")
        exit()
print("No")

Submission status: Runtime Error

Solution code:
# ABC 054 B

import sys

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

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

ret = [[] for i in range(M)]

for i in range(len(B)):
    for j in range(len(A)):
        f = -1
        while True:
            f = A[j].find(B[i], f+1)
            if f == -1:
                break

            ret[i].append((j, f))

flag = False

# ret = [[(1, 1)],
#        [(1, 1), (2, 1)]]

if M == 1 and len(ret[0] > 0):
    print('True')
    sys.exit(0)

for i in range(len(ret[0])):
    start = ret[0][i] # (x, y)

    for j in range(M-1):
        if not (start[0]+1, start[1]) in ret[j+1]:
            break
        if j == M-2:
            print('Yes')
            sys.exit(0)

print('No')

Submission status: Runtime Error

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 s_h in range(n - m):
    for s_w in range(n - m):
        flag = True
        for i in range(m):
            for j in range(m):
                if a[s_h + i][s_w + j] != b[i][j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            break
    if flag:
        break
if not flag:
    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)]
ans="No"
for i in range(N-M+1):
  for j in range(len(A[0])-len(B[0])+1):
    t = 0
    for k in range(len(B[0])):
      for l in range(M):
        if A[k+q][l+p] == B[q][p]:
          t += 1
    if t==len(B[0])*M:
      ans="Yes"
      exit()
print(ans)

Submission status: Runtime Error

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(len(A[0])-len(B[0])+1):
    t = 0
    for k in range(len(B[0])):
      for l in range(M):
        if A[k+q][l+p] == B[q][p]:
          t += 1
    if t==len(B[0])*M:
      ans="Yes"
      break
print(ans)

Submission status: Runtime Error

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)])
f = 0

for i in range(N-M+1):
  for j in range(N-M+1):
    if (A[i:i+M,j:j+M]==B).all():
      f = 1

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

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
i1=[input() for _ in range(n)]
i2=[input() for _ in range(m)]
ans="No"
for i in range(n-m+1):
    for j in range(n-m+1):
        if i1[i][j:m+j]==i2[0] and i1[i+1][j:j+m]==i2[1]:
            ans="Yes"
print(ans)

Submission status: Runtime Error

Solution code:
\#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    a -= 2
    b -= 2
    a %= 13
    b %= 13
    if a > b:
        print("Alice")
    elif a < b:
        print("Bob")
    else:
        print("Draw")
    return

#B
def B():
    n, m = LI()
    a = SR(n)
    b = SR(m)
    if a == b:
        print("Yes")
        return
    for y in range(n - m):
        for x in range(n - m):
            if a[y][x] == b[0][0]:
                flg = 0
                for yi in range(m):
                    for xi in range(m):
                        if b[yi][xi] == a[y + yi][x + xi]:
                            continue
                        flg = 1
                        break
                    if flg:
                        break
                if flg:
                    continue
                print("Yes")
                return
    print("No")
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
c = []
d = []
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d.append(list(input()))
for i in range(a-b+1):
    for j in range(a-b+1):
        m = n = 0
        o = True
        for k in range(i,i+b):
            n = 0
            for l in range(k, k+b):
                if c[k][l] != d[m][n]:
                    o = not o
                n += 1
            m += 1
        if o:
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
c = []
d = ""
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d += input()
e = []
for i in range(b):
    for j in range(b):
        f = ""
        for k in range(b):
            for l in range(b):
                f += c[i+k][j+l]
        e.append(f)
print("Yes" if d in e else "No")

Submission status: Runtime Error

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


for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if li_a[i+x][j:j+m] != li_b[x][:]:
                break
        else:
            print("Yes")
            exit()
            
print("No")

Submission status: Runtime Error

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

    for row in range(n - m + 1):
        current_index = 0
        for index in range(m - 1):
            current_index = a[row].find(b[row], index)
            if current_index < 0:
                break

            for i in range(m - 1):
                if a[row + i].find(b[row + i]) != current_index:
                    break
            else:
                print('Yes')
                return

    print('No')


if __name__ == "__main__":

    main()

Submission status: Runtime Error

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

    for row in range(n - m):
        current_index = 0
        for index in range(m - 1):
            current_index = a[row].find(b[row], index)
            if current_index < 0:
                break

            for i in range(row, n - m):
                if a[i].find(b[i]) != current_index:
                    break
            else:
                print('Yes')
                return

    print('No')


if __name__ == "__main__":

    main()