def can_rearrange(n, k, s, t): # Group positions by their remainder modulo K groups = [[] for _ in range(k)] for i in range(n): groups[i % k].append(i) # For each group, check if the characters in the source can be rearranged to match the target for group in groups: source_chars = [s[i] for i in group] target_chars = [t[i] for i in group] # Sort both lists to check if they contain the same elements source_chars.sort() target_chars.sort() # If the sorted lists don't match, the rearrangement is impossible if source_chars != target_chars: return False return True def main(): # Read input n, k = map(int, input().split()) s = [] for _ in range(n): s.append(input()) t = [] for _ in range(n): t.append(input()) # Check if rearrangement is possible if can_rearrange(n, k, s, t): print("Yes") else: print("No") if __name__ == "__main__": main()