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

Submission status: Wrong Answer

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

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

for i in range(N - M +1):
    for j in range(N - M +1):
        count = 0
        for row in range(M):
            for col in range(M):
                if B[row][col] == A[i + row][j + col]:
                    count += 1
        if count == M * M:
            ans == 'Yes'

print(ans)

Submission status: Wrong Answer

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

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

for i in range(N - M +1):
    for j in range(N - M +1):
        count = 0
        for row in range(M):
            for col in range(M):
                if B[row][col] == A[i + row][j + col]:
                    count += 1
        if count == N*M:
            ans == 'Yes'

print(ans)

Submission status: Wrong Answer

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

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

for i in range(N - M +1):
    for j in range(N - M +1):
        count = 0
        for row in range(M):
            for col in range(M):
                if B[row][col] == A[i + row][j + col]:
                    count += 1
        if count == N*M:
            ans == 'Yes'
        
print(ans)

Submission status: Wrong Answer

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

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

for i in range(N - M +1):
    for j in range(N - M +1):
        count = 0
        for row in range(M):
            for col in range(M):
                if B[row][col] == A[i + row][j + col]:
                    count += 1
        if count == N*M:
            print('Yes')
        else:
            print(ans)

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):
    if a[i:i+m][j:j+m] == b[:]:
      print("Yes")
      exit()
print("No")

Submission status: Wrong Answer

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

A = []
B = []

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


for i in range(N - M + 1):
    for j in range(N - M + 1):
        l = 0
        for l in range(M):
            if A[i].find(B[l],j) != j:
                break   
            if l == M-1:
                print("Yes")
                exit()

print("No")

Submission status: Wrong Answer

Solution code:

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

A = []
B = []

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


for i in range(N - M + 1):
    for j in range(N - M + 1):
        l = 0
        for l in range(M):
            if A[i].find(B[l],j) != j:
                break
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

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

A = []
B = []

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


for i in range(N):
    for j in range(N-M):
        l = 0
        for l in range(M):
            if A[i].find(B[l],j) != j:
                break
            print("Yes")
            exit()

print("No")

Submission status: Wrong Answer

Solution code:

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

A = []
B = []

for i in range(N):
    A.append(input())
for j in range(M):
    B.append(input())
    
start = 0
j = 0
n1 = 0
m1 = 0

for i in range(N):
    if j == M:
        print("Yes")
        exit() 

    x = A[i].find(B[j],start)
    if x == start:
        if j == 0:
            n1 = i
            m1 = start
        j = j + 1
      
    else:
        if j ==0 and start + 1 <= N - M + 1:
            start = start + 1
        elif j !=0 :
            i = n1-1
            start = m1 + 1
            j = 0
print("No")

Submission status: Wrong Answer

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

A = []
B = []

for i in range(N):
    A.append(input())
for j in range(M):
    B.append(input())
    
start = 0
j = 0
n1 = 0
m1 = 0

for i in range(N):
    if j == M:
        print("Yes")
        exit() 

    x = A[i].find(B[j],start)
    if x == start:
        if j == 0:
            n1 = i
            m1 = start
        j = j + 1
      
    else:
        if j ==0 and start + 1 <= N - M + 1:
            start = start + 1
        elif j !=0 :
            i = n1-1
            start = m1 + 1
print("No")

Submission status: Wrong Answer

Solution code:

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

A = []
B = []

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

j = 0
start = 0

for i in range(N):
    if j == M:
            print("Yes")
            exit()
    x = A[i].find(B[j],start)
    if x == start:
        start = x
        j = j + 1
    else:
        start = 0
        j = 0
print("No")

Submission status: Wrong Answer

Solution code:
import sys
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):
    new_list = [a_list[k][i:i+m] for k in range(i,i+m)]
    if(new_list == b_list):
        print('Yes')
        sys.exit()
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)]

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

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

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

print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

#C
def C():
    return

#D
def D():
    return

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

Submission status: Wrong Answer

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

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

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

#C
def C():
    return

#D
def D():
    return

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
c = []
d = []
for i in range(a):
    c.append(list(input()))
for i in range(b):
    d.append(list(input()))
for i in range(a-b+1):
    for j in range(a-b+1):
        m = n = 0
        o = True
        for k in range(i, i+b):
            n = 0
            for l in range(j, j+b):
                if c[k][l] != d[m][n]:
                    o = not o
                n += 1
            m += 1
        if o:
            print("Yes")
            exit()
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 = "No"
for i in range(N-M):
	for j in range(N-M):
		C = [A[x][i:i+M] for x in range(M)]
		if B == C:
			ans = "Yes"

print(ans)

Submission status: Wrong Answer

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


for i in range(n-m+1):
    cnt = 0
    while True:
        s = li_a[i+cnt].rfind(li_b[cnt])
        if s == -1:
            cnt = -1
            break
        if cnt != 0 and tmp != s:
            cnt = -1
            break
        cnt += 1
        tmp = s
        if cnt == m:
            print("Yes")
            exit()
if cnt == -1:
    print("No")

Submission status: Wrong Answer

Solution code:
def main():
    n,m=map(int,input().split(' '))
    a = []
    b = []
    ans = True
    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:j+m] == b[0]:
                for k in range(m):
                    if a[i+k][j:j+m] != b[k]:
                        ans = False
                        print(False,'F')
                if ans == True:
                    print('Yes')
                    exit()
                ans = True

    print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    n,m=map(int,input().split(' '))
    a = []
    b = []
    ans = True
    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:j+m] == b[0]:
                for k in range(m):
                    if a[i+k][j:j+m] != b[k]:
                        ans = False
                        break
                if ans :
                    print('Yes')
                    exit()
    print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,m=map(int,input().split(' '))
    a = []
    b = []
    ans = True
    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]:
                for k in range(0,m):
                    for l in range(0,m):
                        if a[i+k][j+l] != b[k][l]:
                            ans = False
                if ans == True:
                    print('Yes')
                    exit()
    print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,m=map(int,input().split(' '))
    a = []
    b = []
    ans = True
    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]:
                for k in range(1,m):
                    for l in range(1,m):
                        if a[i+k][j+l] != b[k][l]:
                            ans = False
                if ans == True:
                    print('Yes')
                    exit()
    print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n,m=map(int,input().split(' '))
    a = []
    b = []
    ans = True
    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]:
                for k in range(1,m):
                    for l in range(1,m):
                        if a[i+k][j+l] != b[k][l]:
                            ans = False
                if ans == True:
                    print('Yes')
                    exit()
    print('N0')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def judge() :
    for i in range(N - M + 1) :
        for j in range(N - M + 1) :
            for k in range(M) :
                flg = True
                for l in range(M) :
                    if A[i+k][j+l] != B[k][l] :
                        flg = False
                        break
                if flg :
                    return 'Yes'
                    
    return 'No'
    
print(judge())

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

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[str(input()) for _ in range(n)]
b=[str(input()) for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        tmp=[]
        for k in range(m):
            tmp.append(a[j+k][i:i+m])
        if tmp==b:
            print("YES")
            exit()
print("NO")

Submission status: Wrong Answer

Solution code:
import sys

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

Submission status: Wrong Answer

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

i1 = [ input() for i in range(n) ]
i2 = [ input() for i in range(m) ]

for i in range(0, n - m + 1):
    for j in range(0, n - m + 1):
        if [ x[j:] for x in i1[i:] ] == i2:
            print("Yes")
            exit(0)
print("No")

Submission status: Wrong Answer

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

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

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

    print('No')


if __name__ == "__main__":

    main()

Submission status: Wrong Answer

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

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

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

    print('No')


if __name__ == "__main__":

    main()

Submission status: Wrong Answer

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

f = lambda x: 1 if x == "#" else 0
A = [list(map(f, input())) for _ in range(N)]
B = [list(map(f, 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: Wrong Answer

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

mat_N = []
for _ in range(N):
    mat_N.append(input())
mat_M = []
for _ in range(M):
    mat_M.append(input())

def chk(y, x):
    for k in range(M):
        if mat_N[y + k][x:M + x] != mat_M[k]:
            return False
    return True

if M <= N:
    for y in range(N-M):
        for x in range(N-M):
            if chk(y, x):
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
    
for i in range(n-m):
    if b[0] in a[i]:
        p=[]
        for j in range(n-m):
            if b[0]==a[i][j:j+m]:
                p.append(j)
        for j in range(1,m):
            for k in p:
                if b[j]!=a[i+j][k:k+m]:
                    p.remove(k)
        if p!=[]:
            print("Yes")
            import sys
            sys.exit()
print("No")

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
    
for i in range(n-m):
    if b[0] in a[i]:
        p=[]
        for j in range(n-m):
            if b[0]==a[i][j:j+m]:
                p.append(i)
        for j in range(1,m):
            for k in p:
                if b[j]!=a[i+j][k:k+m]:
                    p.remove(k)
        if p!=[]:
            print("Yes")
            import sys
            sys.exit()
print("No")

Submission status: Wrong Answer

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

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

ans = 'No'

for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            flg = True
            for l in range(M):
                if A[i+k][j+l] != B[k][l]:
                    flg = False
                    break
            if flg:
                ans = 'Yes'
                break
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N,M = map(int,input().split())

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N,M = map(int,input().split())

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

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

def check():
    for j in range(N-M+1):
        for i in range(N-M+1):
            if B[i] != A[i][j:j+M]:
                break
        else:
            return 1
    return 0


if check():
    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):
    for j in range(N-M):
        t=True
        for x in range(M):
            if A[i+x][j:j+M]!=B[x]:
                t=False
                break
        if t:
            print("Yes")
            quit()
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(0,N-M+1):
    for j in range(0,N-M+1):
        if A[i][j] == B[0][0]:
            count = 0
            for k in range(M):
                if A[i+k][j:j+M+1] == B[k]:
                    count += 1
            if count == M:
                print("Yes")
                exit()
print("No")

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())
image = []
template = ''
for i in range(n):
    image.append(input().rstrip())
for i in range(m):
    template += input().rstrip()

for x in range(n - m + 1):
    target = ''
    for y in range(m):
        target += ''.join(image[y][x:x + m])
    if target == template:
        print('Yes')
        exit()
print('No')

Submission status: Wrong Answer

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
A = []
B = []
for i in range(N):
    A.append(s())
for i in range(M):
    B.append(s())

import sys
row = -1
col = -1
for i in range(N-M+1):
    col = A[i].find(B[0])
    if col >= 0:
        row = i
        break

if col < 0:
    print('No')
    sys.exit()

for i in range(1, M):
    if A[row+i][col:col+M] != B[i]:
        print('No')
        sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
A = []
B = []
for i in range(N):
    A.append(s())
for i in range(M):
    B.append(s())


match = False
for i in range(N-M+1):
    offset = A[i].find(B[0])
    if offset < 0:
        continue
    for j in range(1, M):
        if A[i+j][offset:offset+M] != B[j]:
            break
        if j == M - 1:
            match = True

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

Submission status: Wrong Answer

Solution code:
def abc():
    n, m = map(int, input().split())
    image = []
    template = ''
    for i in range(n):
        image.append(input().rstrip())
    for i in range(m):
        template += input().rstrip()

    for x in range(n-m+1):
        target = ''
        for y in range(m):
            target += ''.join(image[y][x:x+m])
        if target == template:
            print('Yes')
            return
    print('No')


abc()

Submission status: Wrong Answer

Solution code:
def abc():
    n, m = map(int, input().split())
    nmap = []
    template = ''
    for i in range(n):
        nmap.append(input().rstrip())
    for i in range(m):
        template += input().rstrip()

    for x in range(n-m+1):
        target = ''
        for y in range(m):
            target += ''.join(nmap[y][x:x+m])
        if target == template:
            print('Yes')
            return
    print('No')


abc()

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
flag = False
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if [r[j: j+M] for r in A[i: i+M]] == B:
            flag = True
            break
    if flag:
        break
print('YES' if flag else 'NO')

Submission status: Wrong Answer

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

for i in range(n-m+1):
    for j in range(n - m + 1):
        for k in range(m):
            test = True
            if (b[k] != a[i+k][j:len(b[0]) + j + 1]):
                test = False
                break
        if(test):
            r = True

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

Submission status: Wrong Answer

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

for i in range(n-m+1):
    if(r):
        break
    for j in range(n - m + 1):
        if(r):
            break
        for k in range(m):
            test = True
            if (b[k] != a[i+k][j:len(b[0]) + j + 1]):
                test = False
                break
        if(test):
            r = True

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

Submission status: Wrong Answer

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

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[i+k][j+l] != B[k][l]:
                    flag = 0
        if flag:
            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)]
result = 'No'
for i in range(n):
    if a[i].find(b[0]) != -1 and n - i >= m:
        col = a[i].find(b[0])
        result = 'Yes'
        for x in range(1, m):
            if b[x] != a[i+x][col:m]:
                result = 'No'
        if result == 'Yes':
            print(result)
            exit()
print(result)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
A_list = []
for i in range(N):
    A_list.append(input().split())

B_list = []
for j in range(M):
    B_list.append(input().split())

flag = 0

for k in range(N-M+1):
    for l in range(M):
        A = ''.join(A_list[k+l])
        B = ''.join(B_list[l])
        if B in A:
            flag = 0
        else:
            flag = 1
    if flag == 0:
        print("Yes")
        break
if flag == 1:
    print("No")