from collections import defaultdict def main(): import sys input = sys.stdin.read().split() ptr = 0 N, k = int(input[ptr]), int(input[ptr+1]) ptr += 2 A = list(map(int, input[ptr:ptr+N])) ptr += N B = list(map(int, input[ptr:ptr+N])) ptr += N # Check if A and B are permutations if sorted(A) != sorted(B): print("No") return if k == 1 or k == 2: print("Yes") return if k > N: if A == B: print("Yes") else: print("No") return if k % 2 == 1: # Check parity for each element parity_A = defaultdict(list) for idx, x in enumerate(A): parity = (idx + 1) % 2 # 1-based index parity_A[x].append(parity) parity_B = defaultdict(list) for idx, x in enumerate(B): parity = (idx + 1) % 2 parity_B[x].append(parity) # Verify each element's parity counts match for x in parity_A: if sorted(parity_A[x]) != sorted(parity_B.get(x, [])): print("No") return # Also check for elements in B not in A (though sorted check already passed) for x in parity_B: if x not in parity_A: print("No") return print("Yes") else: print("Yes") if __name__ == "__main__": main()