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

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

diff = N-M+1
top = 0
ind = 0
for i in range(0, diff):
    print(i)
    ind = A[i].find(B[0])
    if ind != -1:
        top += i
        break
else:
    print("No")
    sys.exit()
for i in range(0, len(B)):
    if A[i + top].find(B[i]) != ind:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import sys

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

strNs = []
strMs = []

for n in range(N):
	strNs.append(input())
	
for m in range(M):
	strMs.append(input())
	
def check_rest(start_row, col_index):
	for j in range(1,M):
		if col_index != strNs[start_row+j].find(strMs[j]):
			return False
	else:
		return True
		

for i in range(N-M+1):
	tmp = strNs[i].find(strMs[0])
	while tmp >= 0:
		if check_rest(i, tmp):
			print("Yes")
			sys.exit()
		elif tmp + M > N:
			break
		else:
			tmp = strNs[i].find(strMs[0],tmp+1)
			
print("No")

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,raw_input().split())
a = [[0 for i in range(n)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(m)]
z = []
for i in range(n):
    at = list(raw_input())
    a[i] = at
for i in range(m):
    at = list(raw_input())
    b[i] = at
if n == 1:
    if m > 1:
        print "No"
    if m == 1:
        if a == b:
            print "Yes"
            sys.exit(0)
        else:
            print "No"
temp = [[0 for i in range(m)] for j in range(m)]
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            temp[k] = a[i+k][j:j+m]
        if temp == b:
            print "Yes"
            sys.exit(0)
        else:
            temp = [[0 for i in range(m)] for j in range(m)]
print "No"

Submission status: Wrong Answer

Solution code:
import sys

count = 0
N_list = []
M_list = []
for line in sys.stdin:
    line = line.rstrip("\n")
    if count == 0:
        line = line.split(" ")
        N = int(line[0])
        M = int(line[1])
    elif count <= N:
        N_list.append(line)
    else:
        M_list.append(line)
    count+=1
    
    
def judge_match(N_l, M_l):
    count = 0
    for i in range(len(N_l)):
        if M_l[i] in N_l[i]:
            count += 1
    return count

m_count = 0
for i in range(len(N_list)):
    m_count = judge_match(N_list[i:i+len(M_list)], M_list)
    if m_count == len(M_list):
        print("Yes")
        exit(0)
print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
n,m = map(int,input().split())
a = []
for i in range(n):
    a.append(str(input()))
b = []
for i in range(m):
    b.append(str(input()))

f = [0]*m
count = 0
for j in range(m):
    f[j] = a[j].find(b[j])
 
while -1 in f: f.remove(-1)
try:
    if len(f) == 0:
        print('No')
    else:
        count = 0
        for i in range(len(f)):
            count += 1
            if (b[f[i]] in a[f[i]]) == False:
                count =0
        if count == m:
            print('Yes')
        else:
            print('No')
except:
    print('No')

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def main():
    n, m= map(int, raw_input().split())

    a_template = []
    for i in range(0, n):
        a_template.append(raw_input())

    b_template = []
    for i in range(0, m):
        b_template.append(raw_input())

    a_x = len(a_template[0])
    a_y = len(a_template)

    b_x = len(b_template[0])
    b_y = len(b_template)

    move_x = a_x - b_x
    move_y = a_y - b_y

    if move_x < -1 or move_y < -1:
        print "No"

    for i in range(0, move_x):
        for j in range(0, move_y):
            counter = 0
            for k in range(0, b_y):

                if a_template[j+k][i:b_x] == b_template[k]:
                    counter += 1

                if counter == b_y:
                    print "Yes"
                    return

    print "No"

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
n,m = map(int,raw_input().split())
a = [[0 for i in range(n)] for j in range(n)]
b = [[0 for i in range(m)] for j in range(m)]
z = []
for i in range(n):
    at = list(raw_input())
    a[i] = at
for i in range(m):
    at = list(raw_input())
    b[i] = at
temp = [[0 for i in range(m)] for j in range(m)]
for i in range(n-m):
    for j in range(n-m):
        for k in range(m):
            temp[k] = a[i+k][j:j+m]
        if temp == b:
            print "Yes"
            sys.exit(0)
        else:
            temp = [[0 for i in range(m)] for j in range(m)]
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())
c = []
ans = "No"
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(m):
                c.append(a[i + k][j:j + m])
            if c == b:
                ans = "Yes"
print(ans)

Submission status: Wrong Answer

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

f = [0]*m
count = 0
for j in range(m):
    f[j] = a[j].find(b[j])
 
while -1 in f: f.remove(-1)
try:
    if len(f) == 0:
        print('No')
    else:
        flag = 1
        for i in range(len(f)):
            if (b[f[i]] in a[f[i]]) == False:
                flag =0
        if flag == 1:
            print('Yes')
        else:
            print('No')
except:
    print('No')

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]
    a = [raw_input().strip() for row in range(n)]
    b = [raw_input().strip() for row in range(m)]
    row = col = 0

    for a_i in a:
        flag = True
        while flag:
            if 0 < row and a_i.find(b[row]) != col:
                row = col = 0
            else:
                if 0 < row or b[0] in a_i:
                    if row == 0:
                        col = a_i.find(b[row])

                    row += 1

                    if row == m:
                        print('Yes')
                        exit(0)

                flag = False

    print('No')

Submission status: Wrong Answer

Solution code:
import sys

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

strNs = []
strMs = []

for n in range(N):
	strNs.append(input())
	
for m in range(M):
	strMs.append(input())
	
def check_rest(start_row, col_index):
	for j in range(1,M):
		if col_index != strNs[start_row+j].find(strMs[j]):
			return False
	else:
		return True
		

for i in range(N-M):
	tmp = strNs[i].find(strMs[0])
	while tmp >= 0:
		if check_rest(i, tmp):
			print("Yes")
			sys.exit()
		elif tmp + M > N:
			break
		else:
			tmp = strNs[i].find(strMs[0],tmp+1)
			
print("No")

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

if M > N:
    print("No")
else:
    diff = N-M
    top = 0
    ind = 0
    for i in range(0, diff):
        top = i
        ind = A[i].find(B[0])
        if ind != -1:
            break
    else:
        print("No")
        sys.exit()
    for i in range(0, len(B)):
        if A[i + top].find(B[i]) != ind:
            print("No")
            break
    else:
        print("Yes")

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

if __name__=="__main__":
   N, M = list(map(int, input().replace("\n","").split(" ")))
   a = [list(map(int, list(input().replace("\n","").replace(".", "1").replace("#", "0")))) for i in range(N)]
   a = np.array(a)
   b = [list(map(int, list(input().replace("\n","").replace(".", "1").replace("#", "0")))) for i in range(M)]
   b = np.array(b)


   for i in range(N - M):
       for j in	range(N - M):
           if((a[i:i+M,j:j+M] == b).all()):
               print("Yes")
               sys.exit(0)
   print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = input().split()

ar = int(n[0])
br = int(n[1])

a = []
b = []
for i in range(0, ar):
    a.append(input())

for j in range(0, br):
    b.append(input())

find = False
for i in range(0, ar - br):
    for j in range(0, ar -br):
        if a[i][j] == b[0][0]:
            same = True
            for k in range(0, br):
                for l in range(0, br):
                    if a[i+k][j+l] != b[k][l]:
                        same = False
                        break
            if same:
                find = True
                break
if find:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

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

check = 0
Flag = False

for s in range(N-M+1):
    for t in range(N-M+1):
        check = 0
        for p in range(M):
            for q in range(M):
                if A[s+p][t+q] == B[p][q]:
                    check += 1
        if check == M**M:
            Flag = True

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

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]
    a = [raw_input().strip() for row in range(n)]
    b = [raw_input().strip() for row in range(m)]
    row = col = 0

    for a_i in a:
        flag = True
        while flag:
            if (row == 0 and b[0] in a_i) or (0 < row and -1 < a_i.find(b[row]) == col):
                if row == 0:
                    col = a_i.find(b[row])

                row += 1

                if row == m:
                    print('Yes')
                    exit(0)
                else:
                    flag = False
            elif 0 < row:
                row = col = 0
            else:
                flag = False

    print('No')

Submission status: Wrong Answer

Solution code:
n = input().split()

ar = int(n[0])
br = int(n[1])

a = []
b = []
for i in range(0, ar):
    a.append(input())

for j in range(0, br):
    b.append(input())

find = False
for i in range(0, ar - br):
    for j in range(0, ar -br):
        if a[i][j] == b[0][0]:
            same = True
            for k in range(0, br):
                for l in range(0, br):
                    if a[i+k][j+l] != b[k][l]:
                        same = False
                        break
            if same:
                find = True
                break
if find:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = input().split()

ar = int(n[0])
br = int(n[1])

a = []
b = []
for i in range(0, ar):
    a.append(input())

for j in range(0, br):
    b.append(input())

find = False
for i in range(0, ar - br):
    idx = a[i].find(b[0])
    if idx != -1:
        match = True
        for j in range(1, br):
            idx2 = a[i + j].find(b[j])
            if idx != idx2:
                match = False
        if match:
            find = True
            break
if find:
    print("Yes")
else:
    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)]

cl = [[] for i in range(n - m + 1)]
for i in range(n - m + 1):
    for j in range(m):
        if not a[i].find(b[j]) == -1:
            c = a[i].find(b[j])
            cl[c].append(j)

if cl == [[0]]:
    print("Yes")
    sys.exit()
for ci in cl:
    if ci == list(range(m)) * (n - m):
        print("Yes")
        sys.exit()

print("No")

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input().strip())

    b = list()

    for row in range(m):
        b.append(raw_input().strip())

    row = col = 0

    for ar in a:
        flag = True
        while flag:
            if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
                if row == 0:
                    col = ar.find(b[row])

                row += 1

                if row == m:
                    print('Yes')
                    exit(0)
                else:
                    flag = False
            elif 0 < row:
                row = col = 0
            else:
                flag = False

    print('No')

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input())

    b = list()

    for row in range(m):
        b.append(raw_input())

    row = col = 0

    for ar in a:
        flag = True
        while flag:
            if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
                if row == 0:
                    col = ar.find(b[row])

                row += 1

                if row == m:
                    print('Yes')
                    exit(0)
                else:
                    flag = False
            elif 0 < row:
                row = col = 0
            else:
                flag = False

    print('No')

Submission status: Wrong Answer

Solution code:
n,m = map(int, raw_input().split())
n_list = [] #row major format
m_list = []
for i in range(0, n):
	n_list.append(raw_input())

for x in range(0, m):
	m_list.append(raw_input())

def match_first_rows(n_start):
	result = (-1,-1)
	first_m = m_list[0] # first row
	for x in range(n_start, n):
		n_row = n_list[x]
		if first_m in n_row: # substring matching of first m_row
			j = n_row.index(first_m)
			return (x, j)
	return (-1,-1) #return -1,-1 if none found

# given the leftmost corner of matching in matrix n, start matching each row to see if there is a potential match
# only guranteed first row match
def begin_matching(i,j):
	nx_start = i
	ny_start = j
	for x in range(0,m):
		n_row_string = n_list[nx_start+x]
		n_string = n_row_string[j:j+m] # align window
		m_string = m_list[x]
		if n_string!=m_string:
			return False
	return True

def find_m():

	found_m = False
	counter = 0
	while(counter<n-m and not(found_m)):

		i,j = match_first_rows(counter)
		if i==-1: 
			#goes through entirety, not returning things at all
			print("No")
			found_m = True
		# found a potential starting point
		else:
			result = begin_matching(i,j)
			if result:
				print("Yes")
				found_m = True
			else:
				#do it again, but one row lower
				counter +=1 

find_m()

Submission status: Wrong Answer

Solution code:
import numpy as	np
import sys

if __name__=="__main__":
   N, M = list(map(int, input().replace("\n","").split(" ")))
   a = [list(map(int, list(input().replace("\n","").replace(".", "1").replace("#", "0")))) for i in range(N)]
   a = np.array(a)
   b = [list(map(int, list(input().replace("\n","").replace(".", "1").replace("#", "0")))) for i in range(M)]
   b = np.array(b)


   for i in range(N - M):
       if((a[i:i+M,i:i+M] == b).all()):
           print("Yes")
           sys.exit(0)
   print("No")

Submission status: Wrong Answer

Solution code:
import sys
input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

if M > N:
    print("No")
else:
    diff = N - M
    breaked = 0
    index = 0
    for i in range(0, len(A)-1):
        l = i
        while l <= i + diff and l < len(B):
            ind = A[i].find(B[l])
            if ind != -1:
                if breaked > 0 and index != ind:
                    print("No")
                index = ind
                breaked += 1
                break
            else:
                if breaked > 0:
                    print("No")
                    sys.exit()
                l += 1
    if breaked == len(B):
        print("Yes")
    else:
        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)]

break_flag = 0
for row in range(0, N-M+1):
    for col in range(0, N-M+1):
        
        for matching_row in range(M):
            if not A[row+matching_row][col:col+M+1] == B[matching_row]:
                break
        else:
            print("Yes")
            break_flag = 1
            break
    if break_flag:
        break
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input())

    b = list()

    for row in range(m):
        b.append(raw_input())

    row = col = 0

    for ar in a:
        flag = True
        while flag:
            if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
                if row == 0:
                    col = ar.find(b[row])

                row += 1

                if row == m:
                    print('Yes')
                    exit(0)
                else:
                    flag = False
            elif 0 < row:
                row = col = 0

    print('No')

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input())

    b = list()

    for row in range(m):
        b.append(raw_input())

    row = col = 0

    for ar in a:
        if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
            if row == 0:
                col = ar.find(b[row])

            row += 1

            if row == m:
                print('Yes')
                exit(0)
        elif 0 < row:
            row = col = 0
            if b[0] in ar:
                col = ar.find(b[row])
                row += 1
                if row == m:
                    print('Yes')
                    exit(0)

    print('No')

Submission status: Wrong Answer

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

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

def match(r, c):
    for i, row in enumerate(range(r, r+M)):
        if A[row][c:c+M+1] != B[i]:
            return False
    return True

ok = 0

for r in range(N-M+1):
    if ok == 0:
        for c in range(N-M+1):
            if match(r, c):
                print("Yes")
                ok = 1
            
if not ok:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

AB = [input() for i in range(0, N + M)]
A = AB[0: N]
B = AB[N:]

if M > N:
    print("No")
elif M == N:
    for a, b in zip(A, B):
        if b not in a:
            print("No")
    else:
        print("Yes")
else:
    diff = N - M
    breaked = 0
    for i in range(0, len(A)-1):
        l = i
        while l <= i + diff and l < len(B):
            if B[l] in A[i]:
                breaked += 1
                break
            else:
                if breaked > 0:
                    print("No")
                    sys.exit()
                l += 1
    if breaked == len(B):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n,m = map(int,raw_input().split())
a = [ raw_input() for _ in xrange(n)]
b = [ raw_input() for _ in xrange(m)]
f = True

for i in xrange(m):
    if not b[i] in a:
        f = False

if f:
    print "Yes"
else:
    print "No"

Submission status: Wrong Answer

Solution code:
from itertools import product

n, m = [int(i) for i in input().rstrip().split()]
AA = [[0 if i == '.' else 1 for i in input().rstrip()] for _ in range(n)]
BB = [[0 if i == '.' else 1 for i in input().rstrip()] for _ in range(m)]

for i_r, i_c in product(range(n - m), range(n - m)):
    for k_r, k_c in product(range(m), range(m)):
        if AA[i_r + k_r][i_c + k_c] == BB[k_r][k_c]:
            continue
        else:
            break
    else:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys

count = 0
N_list = []
M_list = []
for line in sys.stdin:
    if count == 0:
        line = line.split(" ")
        N = int(line[0])
        M = int(line[1])
        count += 1
    elif count <= N:
        N_list.append(line)
    else:
        M_list.append(line)
        
for n_e in N_list:
    for m_e in M_list:
        if not m_e in n_e:
            break
    print("Yes")
    exit(0)
print("No")

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input())

    b = list()

    for row in range(m):
        b.append(raw_input())

    row = col = 0

    for ar in a:
        if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
            if row == 0:
                col = ar.find(b[row])

            row += 1

            if row == m:
                print('Yes')
                exit(0)
        elif 0 < row:
            row = col = 0

    print('No')

Submission status: Wrong Answer

Solution code:
m, n = input().split()
m = int(m)
n = int(n)
a = []
for i in range(m):
  row = input().rstrip()
  x = 0
  for c in row:
    x *= 2
    if c == "#":
      x += 1
  a.append(x)

b = []
for i in range(n):
  row = input().rstrip()
  x = 0
  for c in row:
    x *= 2
    if c == "#":
      x += 1
  b.append(x)
c = 2 ** n
found = False
for i in range(m - n + 1):
  for j in range(m - n + 1):
    if found:
      break
    found = True
    for k in range(n):
      if ((a[i+k] >> (m - n - j)) ^ b[k] % c) != 0:
        found = False
        break
if found:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
tmp = raw_input().split(" ")
N = int(tmp[0])
M = int(tmp[1])

A = []
B = []

for i in range(N):
    A.append(raw_input())

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

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

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input())

    b = list()

    for row in range(m):
        b.append(raw_input())

    row = col = 0

    for ar in a:
        if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
            if row == 0:
                col = ar.find(b[row])

            row += 1

            if row == m:
                print('Yes')
                exit(0)
        elif 0 < row and b[row] in ar:
            row = col = 0

    print('No')

Submission status: Wrong Answer

Solution code:
tmp = raw_input().split(" ")
N = int(tmp[0])
M = int(tmp[1])

A = []
B = []

for i in range(N):
    A.append(raw_input())

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

for i in range(N):
    idx = A[i].find(B[0])
    if idx != -1:
        for j in range(M):
            if idx !=A[i].find(B[j]):
                continue
        print("Yes")
        exit()
print("No")

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

A = [input() for i in range(0, N-1)]
B = [input() for n in range(0, M-1)]

if M > N:
    print("No")
elif M == N:
    for a, b in zip(A, B):
        if b not in a:
            print("No")
    else:
        print("Yes")
else:
    diff = N - M
    breaked = 0
    for i in range(0, len(A)-1):
        l = i
        while l <= i + diff and l < len(B):
            if A[i] == B[l]:
                breaked += 1
                break
            else:
                if breaked > 0:
                    print("No")
                    sys.exit()
                l += 1
    if breaked == len(B):
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input())

    b = list()

    for row in range(m):
        b.append(raw_input())

    row = col = 0

    for i, ar in enumerate(a):
        if m+i<n+2:
            if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
                if row == 0:
                    col = ar.find(b[row])
    
                row += 1
    
                if row == m:
                    print('Yes')
                    exit(0)
            elif 0 < row and b[row] in ar:
                i = j = 0
        else:
            break

    print('No')

Submission status: Wrong Answer

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

f = [0]*m
count = 0
for j in range(m):
    f[j] = a[j].find(b[j])

while -1 in f: f.remove(-1)
if len(f) == 0:
    print('No')
else:
    flag = 1
    for i in range(1,len(f)):
        count += 1
        if count == m-1:
            break
        if f[i] != f[i-1]:
            flag = 0
            count = 0

    if flag == 1 and count == m-1:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

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

for i in range(N-M+1):
    index=A[i].find(B[0])
    if index==-1:
        continue
    for j in range(M):
        if A[i+j][index:index+M+1] !=B[j]:
            break
    else :
        print "Yes"
        break
else:
    print "No"

Submission status: Wrong Answer

Solution code:
import sys

input_num = input().split()
N = int(input_num[0])
M = int(input_num[1])

A = [input() for i in range(0, N-1)]
B = [input() for n in range(0, M-1)]

if M > N:
    print("No")
elif M == N:
    for a, b in zip(A, B):
        if b not in a:
            print("No")
    else:
        print("Yes")
else:
    diff = N - M
    breaked = False
    for i in range(0, len(A)-1):
        l = i
        while l <= i + diff and l < len(B):
            if A[i] == B[l]:
                breaked = True
                break
            else:
                if breaked:
                    print("No")
                    sys.exit()
                l += 1
    if breaked:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

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

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

check = 0
Flag = False

for s in range(N-M+1):
    for t in range(N-M+1):
        for p in range(M):
            for q in range(M):
                if A[s+p][t+q] == B[p][q]:
                    check += 1
        if check == M**M:
            Flag = True
        check = 0

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

Submission status: Wrong Answer

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

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

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

(N, M) = reads()

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

for x in range(N-M):
  for y in range(N-M):
    if all(A[y+j][x:x+M] == B[j] for j in range(M)):
      print("Yes"); exit()

print("No")

Submission status: Wrong Answer

Solution code:
# coding=utf-8

if __name__ == '__main__':
    n, m = [int(s) for s in raw_input().split()]

    a = list()

    for row in range(n):
        a.append(raw_input())

    b = list()

    for row in range(m):
        b.append(raw_input())

    row = col = 0

    for ar in a:
        if (row == 0 and b[0] in ar) or (0 < row and ar.find(b[row]) == col):
            if row == 0:
                col = ar.find(b[row])

            row += 1

            if row == m:
                print('Yes')
                exit(0)
        elif 0 < row and b[row] in ar:
            i = j = 0

    print('No')

Submission status: Wrong Answer

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

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

check = 0
Flag = False

for s in range(N-M+1):
    for t in range(N-M+1):
        for p in range(M):
            for q in range(M):
                if A[s+p][t+q] == B[p][q]:
                    check += 1
        if check == M**M:
            Flag = True

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

Submission status: Wrong Answer

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

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

ball = ''.join(b)

def check():
    for i in range(n):
        if i + m > n:
            continue

        for j in range(n):
            if j + m > n:
                continue

            aall = ""
            for k in range(m):
                aall += a[i+k][j:j+m]

            if aall == ball:
                return True

    return False

ret = "YES" if check() else "NO"
print(ret)