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: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from fractions import gcd

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

def readpic(n):
    res = [[0 for j in range(0,n)]for i in range(0,n)]
    for i in range(0,n):
        t = str(input())
        for j in range(0,n):
            if t[j] == '#':
                res[i][j] = 1
            else:
                res[i][j] = 0
    return res

def test(x,y):
    for i in range(0,m):
        for j in range(0,m):
            if b[i][j] != a[i+x][j+y]:
                return False
    return True

a = readln()
n,m = a[0],a[1]
a = readpic(n)
b = readpic(m)
ans = "No"
for i in range(0,n-m+1):
    for j in range(0,n-m+1):
        if test(i,j):
            ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python

N, M = map(int, input().split())
As = []
Bs = []

ret = 'No'
for n in range(N):
    As.append(input())
for m in range(M):
    Bs.append(input())

for i in range(N-M+1):
    for j in range(N-M+1):
        same = True
        for k in range(M):
            if As[i+k][j:j+M] != Bs[k]:
                same = False
                break
        if same:
            ret = 'Yes'
print(ret)

Submission status: Accepted

Solution code:

def f(a, b):
    for x in range(n - m + 1):
        for y in range(n - m + 1):
            ok = True
            for i in range(m):
                for j in range(m):
                    if b[i][j] != a[i + x][j + y]:
                        ok = False
                    if not ok:
                        break
                if not ok:
                    break
            if ok:
                return 'Yes'
    return 'No'


n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
print(f(a, b))

Submission status: Accepted

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):
        flag = True
        for k in range(m):
            for l in range(m):
                if b[k][l] != a[k + i][l + j]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            exit()
print("No")

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
A = [raw_input() for i in xrange(n)]
B = [raw_input() for i in xrange(m)]

for i in xrange(n-m+1):
    for j in xrange(n-m+1):
        ok = 1
        for x in xrange(m):
            for y in xrange(m):
                if A[i+x][j+y] != B[x][y]:
                    ok = 0
        if ok:
            print "Yes"
            exit(0)
print "No"

Submission status: Accepted

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

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

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

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import itertools


def judge(n, m, fig_a, fig_b):
    for dr, dc in itertools.product(range(n - m + 1), repeat=2):
        g = itertools.product(range(m), repeat=2)
        if all(fig_a[r0 + dr][c0 + dc] == fig_b[r0][c0] for r0, c0 in g):
            return True
    return False


def main():
    n, m = (int(x) for x in input().split())
    fig_a = [[c == "#" for c in input()] for _ in range(n)]
    fig_b = [[c == "#" for c in input()] for _ in range(m)]
    print("Yes" if judge(n, m, fig_a, fig_b) else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin

n, m = map(int, stdin.readline().split())
A = []
B = []
for _ in range(n):
    A.append(stdin.readline().strip())
for _ in range(m):
    B.append(stdin.readline().strip())


def is_in(B, A):
    def cmp(A, B, x, y):
        for i in range(m):
            for j in range(m):
                if A[i+y][j+x] != B[i][j]:
                    return False
        return True

    x_shift = len(A[0]) - len(B[0])
    y_shift = len(A) - len(B)
    for x in range(0, x_shift+1):
        for y in range(0, y_shift+1):
            result = cmp(A, B, x, y)
            if result:
                return True
    return False

if is_in(B, A):
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:

n, m = list(map(int, input().split()))
a = ['' for i in range(n)]
b = ['' for i in range(m)]

for i in range(n):
    a[i] = list(input())

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

ans = False

for i in range(n - m + 1):
    for j in range(n - m + 1):
        _a = a[i:i+len(b)]
        _a = list(map(lambda x: x[j:j+len(b)], _a))

        if b == _a:
            ans = True

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

Submission status: Accepted

Solution code:
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def check(i, j, a, b):
    for x in range(len(b)):
        for y in range(len(b)):
            if a[i+x][j+y] != b[x][y]:
                return False
    return True

def main():
    n, m = reads();
    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):
            if check(i, j, a, b):
                print('Yes')
                return
    print('No')
 
main()

Submission status: Accepted

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

    for i in range(n):
        a[i] = input()
    for i in range(m):
        b[i] = input()

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

            if same:
                return 'Yes'

    return 'No'

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

ans=False
for i in range(n-m+1):
    for j in range(n-m+1):
        flag=True
        for mi in range(m):
            for mj in range(m):
                if a[i+mi][j+mj]!=b[mi][mj]:
                    flag=False
        if flag:
            ans=True

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, M = map(int,raw_input().split())
A = [raw_input() for i in xrange(N)]
B = [raw_input() for i in xrange(M)]

for i in xrange(N - M + 1):
    for j in xrange(N - M + 1):
        same = True
        for y in xrange(M):
            for x in xrange(M):
                if A[i + y][j + x] != B[y][x]: same = False
            if not same: break
        if same:
            print "Yes"
            exit()
print "No"

Submission status: Accepted

Solution code:


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

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 A[i+k][j+l] != B[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print('Yes')
            exit()

print('No')

Submission status: Accepted

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):
        flag = True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    flag = False
                    break
            if not flag:
                break
        if flag:
            print("Yes")
            exit()
print('No')

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    A, B = [], []
    for _ in range(N):
        a = input()
        A.append(a)
    for _ in range(M):
        b = input()
        B.append(b)

    for y in range(N):
        for x in range(N):

            ok = True
            for ys in range(M):
                for xs in range(M):
                    if y + ys < N and x + xs < N:
                        if A[y + ys][x + xs] == B[ys][xs]:
                            pass
                        else:
                            ok = False
                    else:
                        ok = False

            if ok:
                print("Yes")
                return
    print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A = [raw_input() for _ in xrange(n)]
B = [raw_input() for _ in xrange(m)]

for r in xrange(n-m+1):
    for c in xrange(n-m+1):
        f = True
        for x in xrange(m):
            for y in xrange(m):
                if A[r+x][c+y] != B[x][y]:
                    f = False
                    break
            if not f:
                break
        if f:
            print "Yes"
            exit()
print "No"

Submission status: Accepted

Solution code:
N,M = map(int, raw_input().split())
A = [raw_input() for _ in range(N)]
B = [raw_input() for _ in range(M)]
for y in range(N-M+1):
  for x in range(N-M+1):
    ok = True
    for yy in range(M):
      for xx in range(M):
        if A[y+yy][x+xx] != B[yy][xx]:
          ok = False
    if ok:
      print "Yes"
      exit(0)
print "No"

Submission status: Accepted

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

A = []
for _ in range(N):
  A.append(input().strip())
B = []
for _ in range(M):
  B.append(input().strip())

def f():
  for i in range(N - M + 1):
    for j in range(N - M + 1):
      same = True
      for ii in range(M):
        for jj in range(M):
          if B[ii][jj] != A[i + ii][j + jj]:
            same = False
      if same:
        print("Yes")
        return 
  print("No")

f()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()

n,m = na()
ba = []
for i in range(n):
    ba.append(ns())
bb = []
for i in range(m):
    bb.append(ns())

for i in range(n-m+1):
    for j in range(n-m+1):
        ok = True
        for k in range(m):
            if ba[i+k][j:j+m] != bb[k]:
                ok = False
                break
        if ok:
            print("Yes")
            sys.exit(0)
print("No")

Submission status: Runtime Error

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

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

ly = len(t[0])
lt = m
ans = False
for i in range(n):
  for j in range(n):
    for k in range(lt):
      if ma[i + k][j : j + ly + 1] != t[k]:
        break
    else:
      ans = True

if ans:
  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)]
ans="No"
for i in range(n-m+1):
  for j in range(n-m+1):
    if [line[j:j+m] for line in a[i:i+m]]==B:
      ans="Yes"
      break
  if ans=="Yes":
    break
print(ans)

Submission status: Runtime Error

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

B = []
for _ in range(M):
    b = input()
    B.append(b)

idx = [0, 0]
while True:
    if idx[0] == N - 1 and idx[1] == N:
        break
    if A[idx[0]][idx[1]] == B[0][0]:
        check = False
        for i in range(M):
            for j in range(M):
                if 0 <= idx[0] + i < N and 0 <= idx[1] + j < N:
                    if A[idx[0] + i][idx[1] + j] != B[i][j]:
                        check = True
                        break
                else:
                    check = True
                    break
            if check:
                break

        if not check:
            print('Yes')
            exit()
    if idx[1] < N - 1:
        idx[1] += 1
        continue
    else:
        idx[0] += 1
        idx[1] = 1
        continue

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(N):
  B.append(input())
f = 0
for i in range(N - M + 1):
  for j in range(N - M + 1):
    g = 0
    for k in range(M):
      for l in range(M):
        if A[i+k][j+l] != B[k][l]:
          g = 1
          break
      if g == 1:
        break
    if g == 0:
      print("Yes")
      f = 1
      break
  if f == 1:
    break
if f == 0:
  print("No")

Submission status: Runtime Error

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n,m = I()
a = [v() for i in range(n)]
b = [v() for i in range(m)]

for j in range(m):
    place = []
    for i in range(n-m):
        if b[j] in a[i]:
            m_place = re.match(b[j],a[i])
            xxx = m_place.span()
            place.append(xxx)
    ans = list(set(place))
    if len(ans) == 1:
        print("Yes")
        sys.exit()

print("No")

Submission status: Runtime Error

Solution code:
A, B = map(int, input().split())
a_lst = []
for i in range(A):
    a_lst.append(input().replace('#', '1').replace('.', '0'))
b_lst = []
for i in range(B):
    b_lst.append(input().replace('#', '1').replace('.', '0'))

for i in range(len(a_lst)):
    if len(a_lst)-i < len(b_lst):
        break
    if b_lst[0] in a_lst[i]:
        idx = a_lst[i].index(b_lst[0])
        for j in range(1, len(b_lst)):
            if b_lst[j] in a_lst[i+i] and a_lst[i+1].index(b_lst[j]) == idx:
                continue
            else:
                break
        else:
            print('Yes')
            exit()

print('No')

Submission status: Runtime Error

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

cnt=0
k=0
flag=0
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

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

if flag==0:
    print("No")

Submission status: Runtime Error

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

for i in range(n-m+1):
  for j in range(n-m+1):
    if x[i][j]==y[0][0]:
      if m==1:
        print('Yes')
        exit()
      for k in range(m):
        if x[i+k][j:j+n-m+1]!=y[k]:
          continue
          
        print('Yes')
        exit()
        
print('No')

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a = []
c = []
for i in range(N):
    b = list(input())
    a+=b
for i in range(M):
  b = list(input())
  c+=b
#print(c,a)
f = False
for i in range(N*N):
  if f == True:
    break
  if N*N-i<M*M:
    break
  count=0
  flag = True
  #print(i,c[0],a[i])
  if c[0] == a[i]:
    if N-((i)%N)<M:
      continue
    num = i
    for j in range(M):
      for k in range(M):
        #print(c[count],a[num])
        if c[count] == a[num]:
          
          num+=1
          count+=1
        elif c[count]!=a[num]:
          flag =False
          break
      num+=N-M
      if flag == False:
        #print(i)
        break  
      if j == M-1:
        f = True
            
  else:
    continue
if f == False:
  print('No')
else:
  print('Yes')

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a = []
c = []
for i in range(N):
    b = list(input())
    a+=b
for i in range(M):
  b = list(input())
  c+=b
f = False
for i in range(N*N):
  if f == True:
    break
  if N*N-(i)<M*M:
    break
  count=0
  flag = True
  #print(i,c[0],a[i])
  if c[0] == a[i]:
    if N-((i)%N)<M:
      continue
    num = i
    for j in range(M):
      for k in range(M):
        #print(c[count],a[num])
        if c[count] == a[num]:
          
          num+=1
          count+=1
        elif c[count]!=a[num]:
          flag =False
          break
      num+=N-M
      if flag == False:
        #print(i)
        break  
      if j == M-1:
        f = True
            
  else:
    continue
if f == False:
  print('No')
else:
  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)]


def serch(x0, y0):
  for i in range(M):
    for j in range(M):
      if A[x0+i][y0+j] != B[i][j]:
        return False
  return True

if M > N:
  print('No')
  exit()


for x in range(N):
  for y in range(N):
    if not serch(x,y):
      continue
    else:
      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)]


def serch(x0, y0):
  for i in range(M):
    for j in range(M):
      if A[x0+i][y0+j] != B[i][j]:
        return False
  return True

if M > N:
  print('No')
  exit()

for b in B:
  for x in range(N):
    for y in range(N):
      if not serch(x,y):
        continue
      else:
        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)]


def serch(x0, y0):
  for i in range(M):
    for j in range(M):
      if A[x0+i][y0+j] != B[i][j]:
        return False
  return True


for b in B:
  for x in range(N):
    for y in range(N):
      if not serch(x,y):
        continue
      else:
        print('Yes')
        exit()
print('No')

Submission status: Runtime Error

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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

for i in range(N):
    for j in range(N):
        if check(i, j):
            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)]

flg = False
for i in range(n - m + 1):
    for j in range(n - m + 1):
        if a[i][j : j + m] == b[0]:
            for k in range(i + 1, i + m):
                if a[k][j : j + m] != b[k]:
                    break
            else:
                print("Yes")
                flg = True
                break
    if flg:
        break
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)]


for i in range(N-M):
    for j in range(N-M):
        flg = True
        for k in range(M):
            for l in range(M):
                if A[i+k][j+l] == B[k][l]:
                    pass
                else:
                    flg=False
                    break
            if flg==False:
                break

        if flg:
            break
    if flg:
        break
if flg:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
def template_matching():
    # 入力
    N, M = map(int, input().split())
    A = list()
    B = list()
    for _ in range(N):
        dummy = input()
        A.append(dummy)
    for _ in range(M):
        dummy = input()
        B.append(dummy)
    # 比較
    for i in range(M):
        for j in range(N):
            # M*Mの一行目がN*Nのいずれかの列に含まれるか
            if B[i] in A[j]:
                row = A[j].find(B[i])
                line = j
                # 正方形を含むか否か
                for k in range(M):
                    if B[k] == A[line+k][row:row+M]:
                        include = True
                    else:
                        include = False
                        break
                if include:
                    return True
    return False

# 出力
if template_matching():
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    A = [iss() for _ in range(N)]
    B = [iss() for _ in range(M)]

    for i in range(N):
        for j in range(N):
            for b in B:
                if A[i][j:] == b: i += 1
                else:break
            else:
                print('Yes')
                exit()
    else:
        print('No')




if __name__ == '__main__':
    main()

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

for i in range(n):
    for j in range(n):
        t = 1
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l] != b[k][l]:
                    t = 0
        if t == 1:
            print('Yes')
            exit(0)

print('No')

Submission status: Runtime Error

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


    #['#.#', '.#.', '#.#']
    ans = 0
    for n in range(N-1):
        for m in range(M-1):
            if b[n] in a[m]:
                ans+=1
    print("Yes" if ans==len(b) else "No")


abc054_b()

Submission status: Runtime Error

Solution code:
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
A = f[:N]
B = f[N:]
for i in range(N):
    for j in range(N-M+1):
        if A[i][j:j+M] == B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] != B[k]:
                    break
            else:
                print('Yes')
                break
    else:
        continue
    break
else:
    print('No')

Submission status: Runtime Error

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

for i in range(N):
    L=list(input())
    picN.append(L)

for i in range(M):
    L=list(input())
    picM.append(L)

K=N-M

for i in range(K):
    for j in range(K):
        flg=True
        for a in range(M):
            for b in range(M):
                if picN[a+i][b+j]!=picM[a][b]:
                    flg=False
        if flg:
            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)]
s = 0
cnt = 0

for i in range(n-m+1):
    for j in range(n-m+1):
        for x in range(m):
            for y in range(m):
                if a[i+x][j+y] == b[x][y]:
                    s += 1
            if s == m ** 2:
                cnt += 1
            else:
                s = 0
if c > 0:
    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)]

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

for i in range(N-M+1):
    for j in range(N-M+1):
        if comp(i,j):
            flag = True
            break
if flag:
    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)]

cnt = 0
if A < B:
    print('No')
    sys.exit()
else:
    for i in range(N):
        for j in range(M):
            if B[j] in A[i]:
                cnt+=1
                flag = True
            else:
                cnt = 0
                flag = False
        	if cnt == M:
            	break
if flag:
    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)]

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

cnt = 0
if A < B:
    print('No')
else:
    for i in range(M):
        if B[i] in A[i]:
            cnt+=1
            flag = True
        else:
            cnt = 0
            flag = False
        if cnt == M:
            break
if flag:
    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 j 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]:
      if all(A[i+k][j:j+m] == B[k] for k in range(1,M)):
        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 = [intpu() for j 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]:
      if all(A[i+k][j:j+m] == B[k] for k in range(1,M)):
        print("Yes")
        exit()
print("No")

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a_g=[];b_g=[]
for i in range(N):
  a_g.append(list(input()))
for i in range(M):
  b_g.append(list(input()))

for i in range(N-M):
  for j in range(N-M):
    flag=1
    for k in range(M):
      for l in range(M):
        if a_g[k+i][l+j] != b_g[k][l]:
          flag=0
          l=M;k=M
    if flag:
      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 h in range(N-M+1):
        cnt = 0
        for k in range(M):
            for j in range(M):
                if A[i+k][h+j] != B[k][h]:
                    cnt += 1
        if cnt == 0:
            break
if cnt == 0:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

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

  flg=0
  
  for i in range(0 , n):
    while a[i].find(b[0])!=-1:
      ##print("while",a[i])
      start=a[i].find(b[0])
      for j in range(1 , m):
        ##print("i=",i)
        ##print("j=",j)
        ##print("a[i+j]=",a[i+j])
        if a[i+j][start:start+m]!=b[j]:
          break
        if j==m-1:
          flg=1
      if flg==1:
        break
      a[i]=a[i][a[i].find(b[0])+1:]
    if flg==1:
        break
        
  if flg==1:
    print("Yes")
  else:
    print("No")

main()

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for j in range(M)]
for i in range(N):
    for j in range(N-M+1):
        if A[i][j:j+M]==B[0]:
            if all(A[i+k][j:j+M]==B[k] for k in range(1,M)):
                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 j in range(M)]
for i in range(N):
    for j in range(N-M):
        if A[i][j:j+M]==B[0]:
            if all(A[i+k][j:j+M]==B[k] for k in range(1,M)):
                print("Yes")
                exit()
print("No")