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

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

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

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