import sys from collections import Counter # Use fast I/O provided by sys.stdin.readline input = sys.stdin.readline def solve(): """ Solves the Reverse Only problem. Determines if sequence A can be transformed into sequence B using segment reversals of length at least K. """ # Read N and K N, K = map(int, input().split()) # Read sequences A and B # Using list comprehension which can be slightly faster for large inputs A = list(map(int, input().split())) B = list(map(int, input().split())) # Necessary condition: A and B must have the same elements (multiset). # We can check this efficiently using collections.Counter. if Counter(A) != Counter(B): # If multisets differ, transformation is impossible. print("No") return # Check if A is already equal to B. # If so, 0 operations are needed, which is allowed ("at least 0 operations"). # We compare element by element for efficiency. is_same = True for i in range(N): if A[i] != B[i]: is_same = False break if is_same: print("Yes") return # Case 1: N < K # If the length of the sequence N is less than K, no subsegment can have length >= K. # Therefore, no operations are possible. # Since we've already established A != B, it's impossible to transform A to B. if N < K: print("No") return # Case 2: N = K # The only possible operation is reversing a subsegment of length at least K. # Since the maximum possible length is N, and N=K, the only allowed operation # is reversing the entire sequence A (segment [1, N] or indices [0, N-1]). # This operation has length N = K, which satisfies the length constraint (>= K). # Transformation is possible iff B is exactly the reverse of A. if N == K: # Check if B is the reverse of A by comparing A[i] with B[N-1-i] is_reverse = True for i in range(N): if A[i] != B[N - 1 - i]: is_reverse = False break if is_reverse: # If B is the reverse of A, one operation achieves the transformation. print("Yes") else: # If B is not the reverse of A, it's impossible. print("No") return # Case 3: N >= K + 1 # In this case, there are more possible reversal operations available. # We can reverse segments of length K, K+1, ..., up to N. # Based on analysis and examples, it's conjectured that if N >= K+1, # the set of allowed reversals is powerful enough to transform A into any permutation B, # provided they have the same multiset of elements. # This relies on the assumption that the operations generate a sufficiently large group # of permutations (likely the symmetric group or alternating group restricted to the multiset). # While there are theoretical edge cases (like specific parity issues with distinct elements), # this conjecture is often sufficient for typical competitive programming problems. # Since the multisets match and A != B, and N >= K+1, we assume it's possible. print("Yes") # Execute the solve function solve()