from collections import defaultdict, Counter def main(): import sys input = sys.stdin.read().split() ptr = 0 N = int(input[ptr]) ptr += 1 k = int(input[ptr]) ptr += 1 A = list(map(int, input[ptr:ptr+N])) ptr += N B = list(map(int, input[ptr:ptr+N])) ptr += N # Check if the multisets of A and B are the same if Counter(A) != Counter(B): print("No") return # If k is even or 1, output Yes if k % 2 == 0 or k == 1: print("Yes") return # For odd k > 1, check parity of positions for each element def get_parity_counts(arr): counts = defaultdict(lambda: [0, 0]) # [odd_count, even_count] for idx, num in enumerate(arr): pos = idx + 1 # 1-based position if pos % 2 == 1: counts[num][0] += 1 else: counts[num][1] += 1 return counts a_parity = get_parity_counts(A) b_parity = get_parity_counts(B) # Check if all elements have the same parity counts in A and B # First, collect all unique elements from both (though Counter is same) all_elements = set(a_parity.keys()).union(set(b_parity.keys())) for elem in all_elements: a_odd, a_even = a_parity[elem] b_odd, b_even = b_parity.get(elem, [0, 0]) if a_odd != b_odd or a_even != b_even: print("No") return print("Yes") if __name__ == "__main__": main()