def solve(): import sys input = sys.stdin.read data = input().split() idx = 0 N, K = map(int, data[idx:idx+2]) idx +=2 S = data[idx:idx+N] idx +=N T = data[idx:idx+N] # Check for each equivalence class modulo K for i in range(K): # Collect elements from S and T for positions i, i+K, i+2K, etc. s_group = [] t_group = [] pos = i while pos < N: s_group.append(S[pos]) t_group.append(T[pos]) pos += K # Check if the multisets are the same if sorted(s_group) != sorted(t_group): print("No") return print("Yes") solve()