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:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

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

for i in range(N-M+1):
	for j in range(N-M+1):  #左上野ますが(i, j)
		tmp_lis = []
		for k in range(M):
			tmp_lis.append(A[i+k][j:j+M])
		if tmp_lis == B:
			print("Yes")
			exit()
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(N)]

for i in range(N-M+1):
  for j in range(N-M+1):
    
    for k in range(M):
      if A[i+k][j:j+M] != B[k]:
        break
    else:
      print('Yes')
      exit()
      
    break

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

h = len(b)
w = len(b[0])

for i in range(h):
    for j in range(w):
        tmp = []
        for k in range(h):
            tmp.append(a[i + k][j : j + w])
        if b == tmp:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Submission status: Runtime Error

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

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

for i in range(N):
    offset = 0
    while offset + M <= N:
        pos = A[i][offset:].find(B[0])        
        if -1 == pos:
            break
        offset += pos
        for j in range(1,M):
            if 0 != A[i+j][offset:].find(B[j]):
                offset += 1
                break
        else:
            print('Yes')
            exit()
else:
    print('No')

Submission status: Runtime Error

Solution code:
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):
        cnt=0
        if A[i][j:j+M] ==B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] == B[k]:
                    cnt+=1
            if cnt==M-1:
                ans='Yes'
                
print(ans)

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    n = []
    for _ in range(N):
        n.append(list(readline()[:-1]))
    m = []
    for _ in range(M):
        m.append(list(readline()[:-1]))

    s = N - M
    for i in range(s):
        for j in range(s):
            flag = True
            for k in range(M):
                if n[i+k][j:j+M] != m[k]:
                    flag = False
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        print('Yes')
    else:
        print('No')
            
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)

def dfs(idx, end, value, cost, g):
    if idx == end:
        if cost == 0:
            return

        if value not in g:
            g[value] = cost
        else:
            g[value] = min(g[value], cost)

        return

    a, b, c = table[idx]
    dfs(idx + 1, end, value + b * Ma - a * Mb, cost + c, g)
    dfs(idx + 1, end, value, cost, g)

N, Ma, Mb = map(int, input().split())
table = [tuple(map(int, input().split())) for i in range(N)]

g1, g2 = dict(), dict()
dfs(0, N // 2, 0, 0, g1)
dfs(N // 2, N, 0, 0, g2)

inf = 100*40 + 1
ans = inf

if 0 in g1:
    ans = min(ans, g1[0])
if 0 in g2:
    ans = min(ans, g2[0])

for v1, c1 in g1.items():
    if -v1 in g2:
        tmp = c1 + g2[-v1]
        ans = min(ans, tmp)

if ans < inf:
    print(ans)
else:
    print(-1)

Submission status: Runtime Error

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

ans = 'No'
for i in range(N-M+1):
  for j in range(N-M+1):
    sbstr = ''.join(A[i][j:j+M] + A[i+1][j:j+M])
    if B == sbstr:
      ans = 'Yes'

print(ans)

Submission status: Runtime Error

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

nl = [list(input()) for _ in range(n)]

ml = [list(input()) for _ in range(m)]



for i in range (0,n-(n-m)):
    for j in range (0,n-(n-m)):
        if nl[i][j] ==ml[0][0]:
            flag = 1
            for k in range(0,m):
                for l in range(0,m):
                    if nl[i+k][j+l] !=ml[k][l]:
                        flag = 0
            if flag ==1:
                print("Yes")
                exit()
            
print("No")

Submission status: Runtime Error

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

cnt=0
Yes=False
for i in nl:
    if(ml[0] in i):
        idx = i.find(ml[0])
        cnt2=cnt+1
        for j in range(1,m):
            if cnt2>n-1:
                ok = False
                break
            elif(not ml[j]==nl[cnt2][idx:idx+m]):
                ok=False
                break
            elif(j==m-1):
                Yes = True
                break
            cnt2+=1
    if(Yes):
        break
    cnt+=1
if Yes:
    print("Yes")
else:
    print("No")

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)])
for i in range(N):
    for j in range(N):
        check = A[i:i+M,j:j+M]
        print(check)
        if (check == B).all():
            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 i in range(N)])
B = np.array([list(input()) for i in range(M)])
for i in range(M):
    for j in range(M):
        check = A[i:i+M,j:j+M]
        if (check == B).all():
            print("Yes")
            exit()
print("No")

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

res=0
for i in range(0,n-m+1):
  keep=0
  for j in range(i,i+m):
    if b[j-i] in a[j]:
      keep+=1
  if keep==m:
    print("Yes")
    res=1
    break
if res=0:
  print("No")

Submission status: Runtime Error

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

A = [[0]]*(N+1)
A[N] = str("a")*50
B = [[0]]*M

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

judge = False 

if M==1:
    for j in range(M):
        for i in range(N):
            for k in range(N):
                if B[j]==A[i][k]:
                    judge = True


count = 0   
for i in range(N-M+1):
    for j in range(M):
        if B[j]==A[i][i:i+M] and B[j+1]==A[i+1][i:i+M]:
            count += 1
            
            if count == M - 1:
                judge = True
                break
            
if judge == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

A = [[0]]*(N+1)
A[N] = str("a")*50
B = [[0]]*M

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

judge = False 
count = 0   
for i in range(N-M+1):
    for j in range(M):
        if B[j]==A[i][i:i+M] and B[j+1]==A[i+1][i:i+M]:
            count += 1
            
            if count == M - 1:
                judge = True
                break
if judge == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

A = [[0]]*(N+1)
B = [[0]]*M

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

judge = False 
count = 0   
for i in range(N-M+1):
    for j in range(M):
        if B[j]==A[i][i:i+M] and B[j+1]==A[i+1][i:i+M]:
            count += 1
            
            if count == M - 1:
                judge = True
                break
if judge == True:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

A = [[0]]*(N+1)
B = [[0]]*M

for i in range(N):
    A[i] = input()
for j in range(M):
    B[j] = input()
 
count = 0   
for i in range(N-M+1):
    for j in range(M):
        if B[j]==A[i][i:i+M] and B[j+1]==A[i+1][i:i+M]:
            count += 1
            
            if count == M - 1:
                print("Yes")
                break
if count != M-1 or count==0:
    print("No")

Submission status: Runtime Error

Solution code:
n = int(input())
# n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
check = False
for i in range(n):
    if a[i] % 2 != 0:
        check = True
        break
count = 0
while check == False:
    for i in range(n):
        a[i] /= 2
        if a[i] % 2 != 0:
            check = True
            break
    count += 1
print(count)

Submission status: Runtime Error

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

mc = n-m+1
ans = False
for ai in range(0, mc):
  if(ans):
    break
  ind = [x.start() for x in re.finditer(b[0], a[ai])]
  for i in ind:
    if(ans):
      break
    for bi in range(0, mc):
      print(bi,a[ai+bi+1][i:i+m], b[bi+1])
      if(a[ai+bi+1][i:i+m] != b[bi+1]):
        break
      if(bi==mc-1):
        ans = True
if(ans):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

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

mc = n-m+1
tb = [[0]*mc]*mc
ans = False
for ai in range(0, mc):
  if(ans):
    break
  ind = [x.start() for x in re.finditer(b[0], a[ai])]
  for i in ind:
    if(ans):
      break
    for bi in range(1, mc):
      if(a[ai+bi][i:i+m] != b[bi]):
        break
      if(bi==mc-1):
        ans = True
if(ans):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

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

mc = n-m+1
tb = [[0]*mc]*mc
ans = False
for ai in range(0, mc):
  if(ans):
    break
  ind = [m.start() for m in re.finditer(b[0], a[ai])]
  for i in ind:
    if(ans):
      break
    for bi in range(1, mc):
      if(a[ai+bi][i:i+m] != b[bi]):
        break
      if(bi==mc-1):
        ans = True
if(ans):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

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

mc = n-m+1
tb = [[0]*mc]*mc
ans = False
for ai in range(0, mc):
  if(ans):
    break
  ind = [m.start() for m in re.finditer(b[0], a[ai])]
  for i in ind:
    if(ans):
      break
    for bi in range(1, mc):
      if(a[ai+bi][i:i+mc] != b[bi]):
        break
      if(bi==mc-1):
        ans = True
if(ans):
  print('Yes')
else:
  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 i in range(n):
    for j in range(n):
        if a[i][j] == b[0][0] and i + m - 1 < n and j + m - 1 < n:
            flag = 1
            for y in range(i, i + m):
                for x in range(j, j + m):
                    if a[i + y][j + x] != b[y][x]:
                        flag = 0
                        break
                
            if flag == 1:
                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)]
for i in range(n):
    for j in range(n):
        if a[i][j] == b[0][0] and i + m <= n and j + m <= n:
            flag = 1
            for y in range(i, i + m):
                for x in range(j, j + m):
                    if a[i + y][j + x] != b[y][x]:
                        flag = 0
                        break
                
            if flag == 1:
                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))
ans="No"
for y in range(N-M+1):
    for x in range(N-M+1):
        if A[y][x]==B[0][0]:
            cond=True
            for i in range(N-M):
                if A[y+i][x:x+M]!=B[i]:
                    cond=False
                    break
            if cond:
                ans="Yes"
                break
    if ans=="Yes":
        break

print(ans)

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))
ans="No"
for y in range(N-M+1):
    for x in range(N-M+1):
        if A[y][x]==B[0][0]:
            cond=True
            for i in range(N-M):
                if A[y+i][x:x+M]!=B[i]:
                    cond=False
                    break
            if cond:
                ans="Yes"
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)]
lenB = M**2
flg=False

def check(i, j):
    cnt=0
    for k in range(M):
        for l in range(M):
            if A[i+k][i+j] == B[k][l]:
                cnt += 1
    if cnt==M**2:
        return True
    
for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j] == B[0][0]:
            flg = check(i, j)
            
ans='Yes' if flg else 'No'
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
for y in range(n-m+1):
    for z in range(n-m):
        count = 0
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count += 1
                if count == m:
                    print("Yes")
                    exit()
            else:
                count = 0
    print("No")

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
for y in range(n-m+1):
        #print(y)
    for z in range(n-m+1):
        count = 0
        for p in range(m):
            if b[p] == a[y+p][z:(z+m)]:
                count += 1
                    #print("if")
                    #print(count)
                if count == m:
                    print("Yes")
                    exit()
            else:
                count = 0
                    #print("else")
                    #print(count)
else:
    print("No")

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
count = 0
for x in range (m):
    #print(x)
    for y in range(n-m+1):
        #print(y)
        for z in range(n-m+1):
            for p in range(m):
                if b[x+p] == a[y+p][z:(z+m)]:
                    count += 1
                    #print("elif")
                    #print(count)
                    if count == m:
                        print("Yes")
                        exit()
                else:
                    count = 0
                    #print("else")
                    #print(count)
else:
    print("No")

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
count = 0
for x in range (m):
    #print(x)
    for y in range(n-m+1):
        #print(y)
        for z in range(n-m+1):
            if b[x] == a[y][z:(z+m)]:
                for p in range(m):
                    if b[x+p] == a[y+p][z:(z+m)]:
                        count += 1
                        if count == m-1:
                            print("Yes")
                            exit()
else:
    print("No")

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
count = 0
for x in range (m):
    #print(x)
    for y in range(n-m):
        #print(y)
        for z in range(n-m):
            if b[x] == a[y][z:(z+m)]:
                for p in range(m):
                    if b[x+p] == a[y+p][z:(z+m)]:
                        count += 1
                        if count == m-1:
                            print("Yes")
                            exit()
else:
    print("No")

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
count = 0
for x in range (m):
    #print(x)
    for y in range(n-m):
        #print(y)
        for z in range(n-m):
            if b[x] == a[y][z:(z+m)]:
                for p in range(m):
                    if b[x+p] == a[y+p][z:(z+m)]:
                        count += 1
                        if count == m:
                            print("Yes")
                            exit()
else:
    print("No")

Submission status: Runtime Error

Solution code:
 int main(void){
 int N,M;
 cin >> N >> M;

 const int nmmax=50;
 char A[nmmax][nmmax],B[nmmax][nmmax];


 for(int y=0;y<N;++y){
 for(int x=0;x<N;++x){
 cin >> A[y][x];
 }
 }

 for(int y=0;y<M;++y){
 for(int x=0;x<M;++x){
 cin >> B[y][x];
 }
 }

 bool exist=false;

 for(int ly=0;ly<N;++ly){
 for(int lx=0;lx<N;++lx){
 if(ly+M-1>=N or lx+M-1>=N) continue;

 bool match=true;
 for(int y=0;y<M;++y){
 for(int x=0;x<M;++x){
 if(A[ly+y][lx+x]!=B[y][x]) match=false;
 }
 }
 if(match) exist=true;
 }
 }

 if(exist)
 cout << "Yes" << endl;
 else
 cout << "No" << endl;

 return 0;
 }

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
a = [list(input())for i in range(n)]
b = [list(input())for i in range(m)]
count = 0
for x in range (m):
    #print(x)
    for y in range(n):
        #print(y)
        for z in range(n-m):
            #print(z)
            for p in range(m):
                #print(p)
                if b[x+p] == a[y+p][z:(z+m)]:
                    count +=1
                    if count == m:
                        print("Yes")
                        exit()
else:
    print("No")

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[list(input())for i in range(n)]
b=[list(input())for j in range(m)]
for i in range(n-m):
    for x in range(n-m):
        if a[i][x:x+m]==b[i]:
            flag=1
            for j in range(1,m):
                if a[i+j][x:x+m]!=b[i+j]:
                    flag=0
            if flag:
                print("Yes")
                exit()
print("No")

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
a=[list(input())for i in range(n)]
b=[list(input())for j in range(m)]
for i in range(m):
    for x in range(n-m):
        if a[i][x:x+m]==b[i]:
            flag=1
            for j in range(1,m):
                if a[i+j][x:x+m]!=b[i+j]:
                    flag=0
            if flag:
                print("Yes")
                exit()
print("No")

Submission status: Runtime Error

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

isIncluding = False

for a_row in range(n):
    for a_column in range(n):

        if a[a_row][a_column] == b[0][0]:

            isExact = True
            for b_row in range(m):
                for b_column in range(1, m):
                    if b[b_row][b_column] != a[a_row + b_row][a_column + b_column]:
                        isExact = False
                        break
                if not isExact:
                    isExact = True
                    break
            else:
                isIncluding = True
                break
        if isIncluding:
            break
    if isIncluding:
        break

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

Submission status: Runtime Error

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

isIncluding = 'No'
current = 0

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

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

print(isIncluding)

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())#正方形
a= [list(input()) for _ in range(n)] #大
b= [list(input()) for _ in range(m)] #小
m1=0
for i in range(n-m+1): #行
    for j in range(n-m+1): #左からの位置
      if b[i][j+k]==a[i][j] for k in range(n-m+1):m1+=1
        if m1==m:print('Yes') and exit()
        else:pass
      else:print('No')

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())#正方形
a= [list(input()) for n in range(n)] #大
b= [list(input()) for m in range(m)] #小
m1=0
for i in range(n-m+1): #行
    for j in range(n-m+1): #左からの位置
      if b[i][j+k]==a[i][j] for k in range(n-m+1):m1+=1
        if m1==m:print('Yes') and exit()
        else:pass
      else:print('No')

Submission status: Runtime Error

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

check = False
for i in range(n):

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

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

	if check:
		break

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

Submission status: Runtime Error

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

check = False
for i in range(n):

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

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

				check=False
				break
	if check:
		break

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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(m):
    for g in range(m):
        d=[]
        for l in range(m):
            d.append(a[l+i][g:g+m])
        if d==b:
            print("Yes")
            exit()
            
print("No")

Submission status: Runtime Error

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

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

img = init_img(n)

tmp_img = init_img(m)

flg = False

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

    for j in range(n):
        count = 0
        for k in range(m):
            if img[i+k][j:j+m] == tmp_img[k]:
                count += 1

        if count == 3:
            flg = True

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

Submission status: Runtime Error

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

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if x_A+x_B > N or y_A+y_B > N:
                    break
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

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

gridA = [[v for v in input()] for _ in range(N)]
gridB = [[v for v in input()] for _ in range(M)]

for x_A in range(N):
    for y_A in range(N):
        ok = True
        for x_B in range(M):
            for y_B in range(M):
                if gridA[x_A+x_B][y_A+y_B] == gridB[x_B][y_B]:
                    continue
                else:
                    ok = False
                    break
            else:
                continue
            break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

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

ans=0

for i in range(N-M+1):
    for j in range(N-M+1):
        if A[i][j]==B[0][0]:
            for k in range(0,M):
                for l in range(0,M):
                    if A[i+k][j+l]==B[k][l]:
                        ans+=1
                        if ans==M**2:
                            flag=1
                    else:
                        ans=0
                        break
    
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)]
ans = 0
for i in range(n-m+1):
    for j in range(n-m+1):
        temp=0
        for k in range(m):
            for l in range(m):
                if B[k][l]==A[i+k][j+l]:
                    temp+=1
                    ans = max(ans,temp)
                                    
print('Yes' if ans==m*m 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)]
ans = 0
for i in range(n-m):
    for j in range(n-m):
        temp=0
        for k in range(m):
            for l in range(m):
                if B[k][l]==A[i+k][j+l]:
                    temp+=1
                    ans = max(ans,temp)
                                    
print('Yes' if ans==m*m else 'No')

Submission status: Runtime Error

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

    for i in A:
        valmin=10**5
        cnt=0
        for j in B:
            if abs(i[0]-j[0])+abs(i[1]-j[1])<valmin:
                valmin=abs(i[0]-j[0])+abs(i[1]-j[1])
                ans=cnt+1
            cnt+=1
        print(ans)
        
 resolve()

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[i] and B[1] in A[i+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=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]
print(b)
for i in range(N-M+1):
    if B[0]in A[i] and B[1] in A[i+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=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[i] and B[1] in A[i+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")