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:
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(n - m):
            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()

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(n - m):
            current_index = a[row].find(b[row], index)
            if current_index < 0:
                break

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

    print('No')


if __name__ == "__main__":

    main()

Submission status: Runtime Error

Solution code:
n,m=map(int,input().split())
x='No'
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
def c(i,j):
  global m,global a, global b
  for k in range(m):
    for l in range(m):
      if b[k][l]!=a[i+k][j+l]:
        return 0
  return 1
for i in range(n-m+1):
  for j in range(n-m+1):
    if c(i,j)==1:
      x='Yes'
      break
print(x)

Submission status: Runtime Error

Solution code:
#include <iostream>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  char A[50][50], B[50][50];
  for(int i=0; i<N; ++i) scanf("%s", &A[i][0]);
  for(int i=0; i<M; ++i) scanf("%s", &B[i][0]);
  for(int Ay=0; Ay<=N-M; ++Ay)for(int Ax=0; Ax<=N-M; ++Ax)
      if([&](int x, int y){
        for(int i = 0, j = 0; i < M; i+= j >= M ? j=0,1 :j++,0)
          if(A[x+i][y+j] != B[i][j]) return 0;
        return 1;
      }(Ax, Ay))
      {
        cout << "Yes" << endl;
        return 0;
      }
  cout << "No" << endl;
  return 0;
}

Submission status: Runtime Error

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

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

def func():
  for i in range(N-M):
    for j in range(N-M):
      if all(A[i+k][j+l] == B[k][l] for k in range(M) for l in range(M)):
        return True
  return False

print("Yes" if func() else "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(input())
B = []
for i in range(M):
    M.append(input())
A = np.array(A)
B = np.array(B)

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

for i in range(N-M):
    for j in range(N-M):
        if A[i:i+M, j:j+M] == B:
            print('Yes')
            exit()
print('No')

Submission status: Runtime Error

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

for i in range(n - m):
    for j in range(n - m + 1):
        t = True
        for k in range(m):
            #print(dat_a[i + k][j:j+m])
            #print(dat_b[k])
            if dat_a[i + k][j:j+m] != dat_b[k]:
                t = False
                continue
            if t:
                break
        if t:
            break
    if t:
        break

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

Submission status: Runtime Error

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

for i in range(n - m):
    t = True
    for j in range(n - m):
        for k in range(m):
            if dat_a[i+ k][j:j+m] != dat_b[k]:
                t = False
                continue
        if t:
            break
    if t:
        break

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

Submission status: Runtime Error

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

for i in range(n - m):
    t = True
    for j in range(n - m):
        for k in range(m):
            if dat_a[i+ k][j:j+m] != dat_b[k]:
                t = False
                continue
    if t:
        break
print("Yes" if t else "No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

pic1=[]
pic2=[]

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

for j in range(m):
    pic2.append(input())

#print(pic1)
#print(pic2)

ans="No"

for i in range(n-m+1):
    for j in range(n-m+1):
        flag=True
        for k in range(m):
            for l in range(m):
                if pic1[i+k][j+l]!=b[k][l]:
                    flag=False

            if not flag:
                break
        if flag:
            print("Yes")
            exit()

print("No")

Submission status: Runtime Error

Solution code:
#include<iostream>
#include <string>
using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	
	string A[55];
	string B[55];
	
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int j = 0; j < M; j++){
		cin >> B[j];
	}
	
	bool judge = false;
	
	for(int i = 0; i < N - M + 1; i++){
		for(int j = 0; j < N - M + 1; j++){
			for(int k = 0; k < M; k++){
				if(B[k] != A[i + k].substr(j, M)){
					break;
				}
				if(k == M - 1){
					judge = true;
				}
			}
		}
	}
	if(judge){
		cout << "Yes";
	}
	else {
		cout << "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(n-m+1):
        if a[i][j]==b[0][0] and a[i][j+1]==b[0][1] and a[i+1][j]==b[1][0] and a[i+1][j+1]==b[1][1]:
            ans='Yes'
            break
print(ans)

Submission status: Runtime Error

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

tg = [input() for _ in range(N)]

#tmpl0〜M-1
tmpl = [input() for _ in range(M)]

#tg0〜N-Mにつき、tmpl0を探し、一致したら同じ添字のtmpl1~M-1を探す
for i in range(0,N-M+1):
  for j in range(0,N-M+1):
    if tmpl[0] == tg[i][j:j+M]:
      if N == 1:
        print('Yes')
        exit()
      for k in range(i+1,i+M):
        if tmpl[k] != tg[i+k][j:j+M]: break
      else:
        print('Yes')
        exit()
print('No')

Submission status: Runtime Error

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

tg = [input() for _ in range(N)]

#tmpl0〜M-1
tmpl = [input() for _ in range(M)]

#tg0〜N-Mにつき、tmpl0を探し、一致したら同じ添字のtmpl1~M-1を探す
for i in range(0,N-M+1):
  for j in range(0,N-M+1):
    if tmpl[0] == tg[i][j:j+M]:
      for k in range(i+1,i+M):
        if tmpl[k] != tg[i+k][j:j+M]: break
      else:
        print('Yes')
        exit()
print('No')

Submission status: Runtime Error

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

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

#tmpl0〜M-1
tmpl = [list(map(int,input().split())) for _ in range(M)]

#tg0〜N-Mにつき、tmpl0を探し、一致したら同じ添字のtmpl1~M-1を探す
for i in range(0,N-M+1):
  for j in range(0,N-M+1):
    if tmpl[0] == tg[i][j:j+M]:
      for k in range(i+1,i+M):
        if tmpl[k] != tg[i+k][j:j+M]: break
      else:
        print('Yes')
        exit()
print('No')

Submission status: Runtime Error

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

def solve():
    N, M = list(map(int, input().split()))
    A = []
    B = []

    for i in range(N):
        A.append(list(input()))
    for i in range(M):
        B.append(list(input()))
    
    # 左上から順に走査する
    for i in range(N-M+1):
        for j in range(N-M+1):
            if A[i][j] == B[0][0]:
                is_contained = True
                for k in range(i, i+M):
                    for l in range(j, j+M):
                        if A[k][l] != B[k][l]:
                            is_contained = False
                            break
                    if not is_contained: break
                if is_contained:
                    print("Yes")
                    return
    print("No")


if __name__ == "__main__":
    solve()

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(min(N - M + 2, N)):
	for j in range(min(N - M + 2, N)):
		# print("i=", i, "j=", j)
		if A[i][j: j + M] == B[0]:
			for k in range(1, M):
				tmp = True
				if A[i + k][j: j + M] == B[k]:
					pass
				else:
					tmp = False
					break
			if tmp:
				print("Yes")
				exit()
print("No")

Submission status: Runtime Error

Solution code:
N , M = map(int, input().split())
As =[input() for _ in range(N)]
Bs =[input() for _ in range(M)]
m = N-M
for i in range(m):
    for j in range(m):
        flag = True
        for k in range(M):
            for l in range(M):
                if As[k+i][l+j] != Bs[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N , M = map(int, input().split())
As =[input() for _ in range(N)]
Bs =[input() for _ in range(M)]
m = N-M
for i in range(m):
    for j in range(m):
        flag = True
        for k in range(i, M+i):
            for l in range(j, M+j):
                if As[k][l] != Bs[k-i][l-j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            break
    if flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
a = [input() for n in range(N)]
b = [input() for m 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
if flag==1:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

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]):
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

Solution code:
[n,m] = [int(i) for i in input().split()]
a = []
b = []
for i in range(n):
  a.append(input())
for i in range(m):
  b.append(input())
cnt = 0
flag = "No"
for i in range(n - m + 1):
  for j in range(n - m + 1):
    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 = "Yes"
    else:
      cnt = 0
print(flag)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
data = []
for i in range(N):
  data.append(input())
input_data=[]
for i in range(M):
  input_data.append(input())
flag_1 = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    if flag = False
    for k in range(M):
      for l in range(M):
        if data[i+k][j+l] != input_data[k][l]:
          flag = True
    if flag:
      flag_1 = True

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
n = []
m = []
for i in range(N):
  s = str(input())
  row = []
  for j in range(N):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  n.append(row)
for i in range(M):
  s = str(input())
  row = []
  for j in range(M):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  m.append(row)
 
def search(a,b):
  mr = mc = 0
  for r in range(a, a+M):
    for c in range(b, b+M):
      if n[r][c] != m[mr][mc]:
        return False
      mc += 1
    mr += 1 
  return True

ans = 0
for i in range(N-M+1):
  for j in range(N-M+1):
    if search(i,j):
      ans = 1
      break
  if ans:
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

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

def solve(N, M, A, B):
    
    include = False
    for h in range(N-M+1):
        for w in range(N-M+1):
            match = True
            for i in range(M):
                for j in range(M):
                    if(A[h+i][w+j] != B[i][j]):
                        match = False
            if(match):
                include = True
    
    print("Yes" if include else "No")
    
    
if __name__ == '__main__':
    N, M = map(int, input().split())
    A, B = [], []
    for i in range(N):
        A.append(input())
    for j in range(M):
        B.append(input())

    solve(N, M, A, B

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
n = []
m = []
for i in range(N):
  s = str(input())
  row = []
  for j in range(N):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  n.append(row)
for i in range(M):
  s = str(input())
  row = []
  for j in range(M):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  m.append(row)
 
def search(a,b):
  for r in range(a, a+M-1):
    for c in range(b, b+M-1):
      #print(r,c)
      if n[r][c] != m[r][c]:
        return False
  return True
#print(n, m)
ans = 0
for i in range(N-M+1):
  for j in range(N-M+1):
    if search(i,j):
      ans = 1
      break
  if ans:
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
n = []
m = []
for i in range(N):
  s = str(input())
  row = []
  for j in range(N):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  n.append(row)
for i in range(M):
  s = str(input())
  row = []
  for j in range(M):
    if s[i] == "#":
      row.append(1)
    else:
      row.append(0)
  m.append(row)

def search(a,b):
  for r in range(a, a+M):
    for c in range(b, b+M):
      if n[r][c] != m[r][c]:
        return False
  return True
  
ans = 0
for i in range(N-M):
  for j in range(N-M):
    if search(i,j):
      ans = 1
      break
  if ans:
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
A = [input() for _ in [0]*N]
B = [input() for _ in [0]*M]
endFlg = False
for i in range(N-M):
    for j in range(N-M):
        breakFlg = False
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    breakFlg = True
                    break
        if breakFlg: break
        pass
        else: endFlg = True
    if endFlg: break
if endFlg:print("Yes")
else:print("No")

Submission status: Runtime Error

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

for i in range(N-M):
    for j in range(N-M):
        flagx = True
        for x in range(M):
            if(A[i+x][j:j+M]!=B[x]):
                flagx = False
        if(flagx): break

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

l = 0
while l <= len(A[0]) - len(B[0]):
	for i in range(N - M + 1):
		s = A[i][l:]
		if not B[0] in s:
			continue
		if 0 == s.index(B[0]):
			for m in range(1, M):
				if 0 != A[i + m][l:].index(B[m]):
					break
			else:
				print("Yes")
				exit()
	l += 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)]

l = 0
w = len(A[0])
while l <= len(A) - len(B):
	for n in range(len(A) - len(B)):
		if B[0] not in A[n][l:]:
			continue
		if 0 == A[n][l:].index(B[0]):
			for m in range(1, len(B)):
				if 0 != A[n + m][l:].index(B[m]):
					break
				else:
					#print(n, m)
					print("Yes")
					exit()
	l += 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)]

l = 0
w = len(A[0])
while l <= len(A[0]) - len(B[0]):
	for n in range(len(A) - len(B)):
		if B[0] not in A[n][l:]:
			continue
		if 0 == A[n][l:].index(B[0]):
			for m in range(1, len(B)):
				if 0 != A[n + m][l:].index(B[m]):
					break
				else:
					#print(n, m)
					print("Yes")
					exit()
	l += 1
print("No")

Submission status: Runtime Error

Solution code:
import sys

n, m = map(int, input().split())
a_array = [input() for i in range(n)]
b_array = [input() for i in range(m)]

for ai in range(n):
    for aj in range(n):
        can = True
        for bi in range(m):
            if a_array[ai+bi][aj:aj+m] != b_array[bi]:
                can = False
                break
        if can:
            print('Yes')
            sys.exit()

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

for y in range(N-M+1):
    for x in range(N-M+1):
        for k in range(M):
            if A[y+k][x:x+M] != B[y+k]:
                break
        else:
            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)]

for y in range(N-M+1):
    for x in range(N-M+1):
        for k in range(M):
            if A[y+k][x:x+M] != B[y+k]:
                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)]

for y in range(N-M+1):
    for x in range(N-M+1):
        for k in range(M):
            if A[y+k][x:x+M] != B[y]:
                break
        else:
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(input()))
b = []
for _ in range(m):
    b.append(list(input()))
ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        aaa = 0
        for k in range(m):
            if b[k] == a[i][j:j+2]:
                i += 1
                aaa += 1
            else:
                break
        if aaa == m:
            ans = "Yes"
            break
print(ans)

Submission status: Runtime Error

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

match_line = 0
for i in range(n):
  for j in range(n-m):
    for k in range(m):
      if a[i+k][j:j+m] == b[k]:
        match_line += 1
        if match_line >= m:
          print("Yes")
          exit()
      else:
        match_line = 0
        continue
print("No")

Submission status: Runtime Error

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

match_line = 0
for i in range(n):
  for j in range(n-m):
    for k in range(m):
      if a[i+k][j:j+m] == b[k]:
        match_line += 1
        if match_line >= m:
          print("Yes")
          exit()
      else:
        match_line = 0
print("No")

Submission status: Runtime Error

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

ans = [0] * (n-m)
for i in range(n):
  for j in range(n-m):
    if a[i][j:j+m] == b[i]:
      ans[j] += 1
      if ans[j] >= m:
        print("Yes")
        exit()
    else:
      ans[n-m] = 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 i in range(n-m+1):
    for j in range(n-m+1):
        f=True
        for k in range(m):
            for l in range(m):
                if a_list[i+k][j+l]!=b_list[k][l]:
                    f=false
                    break
            if not f:
                break
        if f:
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

Solution code:
def INSTR():
	return input()

def INNUM():
	return int(INSTR())

def INSTR_S():
	return INSTR().split()

def INNUM_S():
	return map(int, INSTR_S())

def INSTR_M(n):
	return [INSTR() for _ in range(n)]

def INNUM_SM(n):
	return [tuple(INNUM_S()) for _ in range(n)]

N, M = INNUM_S()
NPIC = INSTR_M(N)
MPIC = INSTR_M(M)

for i, npic in enumerate(NPIC):
	if MPIC[0] in npic:
		c = npic.find(MPIC[0])
		for j, mpic in enumerate(MPIC):
			if c != NPIC[i + j].find(mpic):
				break
		else:
			print("Yes")
			exit()
print("No")

Submission status: Runtime Error

Solution code:
from sys import exit
n, m = map(int, input().split())
s1 = " ".join([input() for _ in range(n)])
s2 = [input() for _ in range(m)]
flag = True

i = 0
while i < m:
    #try:
        if s1.count(s2[i]) == 0:
            print("No")
            exit()
        ind = s1.index(s2[i])
        s1 = list(s1)
        del s1[ind]
        s1 = "".join(s1)
        if s1[ind+n+1:ind+n+m+1:] == s2[i+1]:
            i += 1
    #except:
        """print("No")
        exit()"""
print("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)]
for i in range(n-m+1):
    for j in range(n-m+1):
        x=[]
        for k in range(m):
            x.append(a[i+k][j+m])
        if x==b:
            print("Yes")
            exit()
print("No")

Submission status: Runtime Error

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

for t in range(n - m+1):
    # if success:
    #     break
    for s in range(n - m+1):
    # cycle 2
        if a[t][s:m] == b[0]:
            # if t+m> n:
            #     continue
            tmp = 0
            for y in range(m):
                 # if not flg:
                #     break
                # for x in range(s, s + m):
                if a[t + y][s:m] == b[y]:
                    # flg = False
                    tmp += 1
            count = max(count, tmp)

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

Submission status: Runtime Error

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

for t in range(n - m+1):
    if success:
        break
    for s in range(n - m+1):
    # cycle 2
        if a[t][s:m] == b[0]:
            if t+m >= n:
                continue
                tmp = 0
            for y in range(m):
                 # if not flg:
                #     break
                # for x in range(s, s + m):
                if a[t + y][s:m] == b[y]:
                    # flg = False
                    tmp += 1
            count = max(count, tmp)

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

Submission status: Runtime Error

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

for t in range(n - m+1):
    if success:
        break
    # for s in range(0, n - m):
        # cycle 2
    if a[t].find(b[0]) != -1:
            if t+m >= n:
                continue
            flg = True
            for y in range(t, t + m):
                # if not flg:
                #     break
                # for x in range(s, s + m):
                    if a[t + y].find(b[y]) == -1:
                        # flg = False
                        break

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

Submission status: Runtime Error

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

for t in range(n - m+1):
    if success:
        break
    # for s in range(0, n - m):
        # cycle 2
    if a[t].find(b[0]) != -1:
            if t+m > n:
                continue
            flg = True
            for y in range(t, t + m):
                # if not flg:
                #     break
                # for x in range(s, s + m):
                    if a[t + y].find(b[y]) == -1:
                        # flg = False
                        break

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

Submission status: Runtime Error

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

for t in range(0, n - m):
    if success:
        break
    # for s in range(0, n - m):
        # cycle 2
    if a[t].find(b[0]) != -1:
            if t+m > n:
                continue
            flg = True
            for y in range(t, t + m):
                # if not flg:
                #     break
                # for x in range(s, s + m):
                    if a[t + y].find(b[y]) == -1:
                        # flg = False
                        break

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

Submission status: Runtime Error

Solution code:
a = []
b = []
flg = False
success = False
n, m = map(int, input().split())
for i in range(0, n):
    a.append(input())
for r in range(0, m):
    b.append(input())
for t in range(0, n - m):
    if success:
        break
    for s in range(0, n - m):
        # cycle 2
        if a[t][s] == b[0][0]:
            flg = True
            for y in range(t, t + m):
                if not flg:
                    break
                for x in range(s, s + m):
                    if t + y > n or s + x > n:
                        flg = False
                        break
                    if a[t + y][s + x] != b[y][x]:
                        flg = False
                        break

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

Submission status: Runtime Error

Solution code:
a = []
b = []
flg = False
success = False
n, m = map(int, input().split())
for i in range(0, n):
    a.append(input())
for r in range(0, m):
    b.append(input())
for t in range(0, n - m):
    if success:
        break
    for s in range(0, n - m):
        # cycle 2
        if a[t][s] == b[0][0]:
            flg = True
            for y in range(t, t + m):
                if not flg:
                    break
                for x in range(s, s + m):
                    if t+y > n or s+x > n or  a[t + y][s + x] != b[y][x]:
                        flg = False
                        break

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

Submission status: Runtime Error

Solution code:
a = []
b = []
flg = False
success = False
n, m = map(int, input().split())
for i in range(0, n):
    a.append(input())
for r in range(0, m):
    b.append(input())
for t in range(0, n - m):
    if success:
        break
    for s in range(0, n - m):
        # cycle 2
        if a[t][s] == b[0][0]:
            flg = True
            for y in range(t, t + m):
                if not flg:
                    break
                for x in range(s, s + m):
                    if a[t + y][s + x] != b[y][x]:
                        flg = False
                        break

if flg:
    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(0, M - N):
  for j in range(0, M - N):
    if A == B[i:i+N+1][j:j+N+1]:
      flag = True
    if flag:
      break
  if flag:
    break
if flag:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
n,m=[int(i) for i in 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(len(b[i])):
        if b[i][j]!=a[i][j]:
            result=True
            break
print("No" if result else "Yes")

Submission status: Runtime Error

Solution code:
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()))
for k in range(N-M+1):
  for l in range(N-M+1):
    cnt = 0
    if B[0][0:M] == A[k][l:l+M]:
      p = k
      q = l
      for m in range(N-M+1):
        if B[m][0:M] == A[p+m][q:q+M]:
          cnt += 1
        if cnt == M:
          print('Yes')
          exit()
print('No')

Submission status: Runtime Error

Solution code:
""" AtCoder """

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

check = True

for i in range(N - M + 1):
    check = True
    for j in range(M):
        count = 0
        for jj in range(N - M + 1):
            if A[i + jj][j:j + M] != B[jj]:
                check = False
                break
            count += 1
        if count == M:
            print("Yes")
            exit()
        if not check:
            break

print("No")