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: Wrong Answer

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

f = False
ff = False

for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(M):
      for l in range(M):
        f = True
        if A[i+k][j+l] != B[k][l]:
          f = False
    if f:
      ff = True
      break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

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

Submission status: Wrong Answer

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

ans = "Yes"

for a1, b1 in zip(A, B):
    for a2, b2 in zip(a1, b1):
        if a2 != b2:
            ans = "No"

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

fl = False
for i in range(n-m+1):
    if b[0] in a[i]:
        tmp = a[i].find(b[0])
        for j in range(1,m):
            if a[i+j][tmp:tmp+m] != b[j]:
                fl = False
                break
            fl = True
    if fl:
        break
if fl:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

flag=False
for a in As[:]:
  cnt=[]
  if Bs[0] in a:
    for i in range(0,n-m+1):
      if Bs[0]==a[i:i+len(Bs[0])]:
        cnt=[i for i in range(i,i+len(Bs[0]))]
        break
  if len(cnt)==2:
    for j in range(len(Bs)):
      if As[j][cnt[0]:cnt[-1]+1]==Bs[j]:
        flag=True
      else:
        flag=False
    if flag:
      break
if flag:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import re

n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for idx_a, arow in enumerate(a[:n-m+1]):
  for idx_obj in re.finditer(b[0], arow):
    falg = True
    for i in range(1,m):
      if b[i] != a[idx_a+i][idx_obj.start():idx_obj.end()]:
        break
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
import re

n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for idx_a, arow in enumerate(a[:n-m+1]):
  for result in re.finditer(b[0], arow):
    start_idx = result.start()
    falg = True
    for i in range(1,m):
      if b[i] != a[idx_a+i][start_idx:m]:
        falg = False
    if falg is True:
      print('Yes')
      exit()
print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for idx_a, arow in enumerate(a[:n-m+1]):
  if b[0] in arow:
    first_idx = arow.index(b[0])
    falg = True
    for i in range(1,m):
      if b[i] != a[idx_a+i][first_idx:m]:
        falg = False
    if falg is True:
      print('Yes')
      exit()
print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for idx_a, arow in enumerate(a):
  if b[0] in arow:
    first_idx = arow.index(b[0])
    for i in range(1,m):
      if b[i] != a[idx_a+i][first_idx:m]:
        break
    print('Yes')
    exit()
print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for brow in b:
  for idx_a, arow in enumerate(a):
    if brow in arow:
      first_idx = arow.index(brow)
      for i in range(1,m):
        if b[i] != a[idx_a+i][first_idx:m]:
          break
      print('Yes')
      exit()
print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [input().strip() for _ in range(n)]
b = [input().strip() for _ in range(m)]
for brow in b:
  for arow in a:
    if brow in arow:
      first_idx = arow.index(brow)
      for i in range(1,m):
        if b[i] != a[i][first_idx:m]:
          break
      print('Yes')
      exit()
print('No')

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for brow in b:
  for arow in a:
    if brow in arow:
      first_idx = arow.index(brow)
      for i in range(1,m):
        if b[i] != a[i][first_idx:m]:
          break
      print('Yes')
      exit()
print('No')

Submission status: Wrong Answer

Solution code:
import sys
n,m=map(int,input().split())
a=[]
b=[]
for x in range(n):
    a.append(input())
for y in range(m):
    b.append(input())
for z in range(n-m+1):
    k=0
    l=0
    for w in range(n-m+1):
        if (a[w])[z:z+m]==b[k]:
            l+=1
            k+=1
            if l==m:
                print('Yes')
                sys.exit()
        print(a[w][z:z+m])
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for x in range(n):
    a.append(input())
for y in range(m):
    b.append(input())
for z in range(n-m):
    for w in range(n-m):
        if (a[w])[z:z+m]!=b[w]:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

s="No"
i=0
for j in range(n):
    if b[i] in a[j]:
        i+=1
    else:
        i=0
    if i==0 and b[i] in a[j]:
        #途中のパターン
        i+=1
    if i==m:
        s="Yes"
        break

print(s)

#めんどいなーーー
#一行ずつ確かめてく

Submission status: Wrong Answer

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

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

s="No"
i=0
for j in range(n):
    if b[i] in a[j]:
        i+=1
    else:
        i=0
        if b[i] in a[j]:
            i+=1
    if i==m:
        s="Yes"
        break

print(s)

#めんどいなーーー
#一行ずつ確かめてく

Submission status: Wrong Answer

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

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

s="No"
i=0
for j in range(n):
    if b[i] in a[j]:
        i+=1
    else:
        i=0
    if i==m:
        s="Yes"
        break

print(s)

#めんどいなーーー
#一行ずつ確かめてく

Submission status: Wrong Answer

Solution code:
m,n=[int(x) for x in str(input()).split()]
s=""
for i in range(m+2):
  s+="0"
A=[s]
for i in range(m):
  A.append("0"+input()+"0")
A.append(s)


s=""
for i in range(n+2):
  s+="0"
B=[s]
for j in range(n):
  B.append("0"+input()+"0")
B.append(s)
#print(A,B)

count=0
for j in range(1,m-n+2):
  for k in range(1,m-n+2):
    ans=1
    for a in range(1,n+1):
      for b in range(1,n+1):
        #print(a,b)
        if A[j+a-1][j+b-1]!=B[a][b]:
          ans=0
    if ans==1:
      count=1
if count==1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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):
    if all([B[j] in A[i+j] for j in range(m)]):
        print('Yes')
        exit()
print('No')

Submission status: Wrong Answer

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

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

c = []

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

Submission status: Wrong Answer

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

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

c = []

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

Submission status: Wrong Answer

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

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

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

ans = False
for y in range(N-M):
  for x in range(N-M):
    matched = True
    for v in range(M):
      for u in range(M):
        if A[y+v][x+u]!=B[v][u]:
          matched = False
    if matched:
      ans = True
print('Yes' if ans else 'No')

Submission status: Wrong Answer

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

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

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

ans = False
for y in range(N-M):
  for x in range(N-M):
    flag = True
    for v in range(M):
      for u in range(M):
        if A[y+v][x+u]!=B[v][u]:
          flag = False
    if flag:
      ans = True
print('Yes' if ans else 'No')

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m=map(int,input().split())

n_grid=np.empty((n,n), dtype="<U")
m_grid=np.empty((m,m), dtype="<U")

for i in range(n):
  s=tuple(input().split())
  n_grid[i]=s
for i in range(m):
  s=tuple(input().split())
  m_grid[i]=s

found=False
for i in range(n-m+1):
  for j in range(n-m+1):
    if (m_grid == n_grid[i:i+m, j:j+m]).all():
      found=True
      break
if found:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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):
        if A[j][i] == B[0][0]:
            flag = True
            for k in range(M):
                if A[j+k][:M] != B[k]:
                    flag = False
            if flag:
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, M: int, A: "List[str]", B: "List[str]"):

    for i in range(N-M):
        for j in range(N-M):
            flag = True
            for k in range(M):
                for l in range(M):
                    if A[i+k][j+l] != B[k][l]:
                        flag = False
                        break
                if flag == False:
                    break
            if flag == True:
                yes()
                return

    no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [next(tokens) for _ in range(N)]  # type: "List[str]"
    B = [next(tokens) for _ in range(M)]  # type: "List[str]"
    solve(N, M, A, B)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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):
    A_new = A[i:i+M]
    for j in range(N-M+1):
        A_new = list(map(lambda n:n[j:j+M], A_new))
        if A_new == B:
            print('Yes')
            exit()
print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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