# coding: utf-8 import sys from collections import defaultdict # defaultdict を使う別解も考えられるが、今回はリストで実装 def solve(): # N と K を読み込む # Read N and K n, k = map(int, sys.stdin.readline().split()) # 初期状態 S を読み込む (0-based index でアクセスするためリストに) # Read initial state S (into a list for 0-based indexing) s = [sys.stdin.readline().strip() for _ in range(n)] # 目標状態 T を読み込む (0-based index でアクセスするためリストに) # Read target state T (into a list for 0-based indexing) t = [sys.stdin.readline().strip() for _ in range(n)] # 各剰余グループ (0 から K-1) ごとにユーザーネームを格納するリストのリスト # List of lists to store usernames for each remainder group (0 to K-1) initial_groups = [[] for _ in range(k)] target_groups = [[] for _ in range(k)] # 初期状態 S を剰余グループに分類 # Classify initial state S into remainder groups for i in range(n): remainder = i % k # Calculate remainder using 0-based index initial_groups[remainder].append(s[i]) # 目標状態 T を剰余グループに分類 # Classify target state T into remainder groups for i in range(n): remainder = i % k # Calculate remainder using 0-based index target_groups[remainder].append(t[i]) # 各剰余グループについて、含まれるユーザーネームの集合が一致するかどうかを判定 # For each remainder group, check if the set of usernames matches possible = True for r in range(k): # 各グループのリストをソートして比較する # Sort the lists for each group and compare them # ソートすることで、要素の集合が一致するかどうかを判定できる # Sorting allows checking if the sets of elements are identical if sorted(initial_groups[r]) != sorted(target_groups[r]): # 一致しないグループが見つかったら、不可能と判断してループを抜ける # If a mismatch is found, determine it's impossible and break the loop possible = False break # 結果を出力 # Print the result if possible: print("Yes") else: print("No") # 関数を実行 # Execute the function solve()