Little Petya likes permutations a lot. Recently his mom has presented him permutation q_1, q_2, ..., q_{n} of length n.

A permutation a of length n is a sequence of integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n), all integers there are distinct. 

There is only one thing Petya likes more than permutations: playing with little Masha. As it turns out, Masha also has a permutation of length n. Petya decided to get the same permutation, whatever the cost may be. For that, he devised a game with the following rules:  Before the beginning of the game Petya writes permutation 1, 2, ..., n on the blackboard. After that Petya makes exactly k moves, which are described below.  During a move Petya tosses a coin. If the coin shows heads, he performs point 1, if the coin shows tails, he performs point 2.  Let's assume that the board contains permutation p_1, p_2, ..., p_{n} at the given moment. Then Petya removes the written permutation p from the board and writes another one instead: p_{q}_1, p_{q}_2, ..., p_{q}_{n}. In other words, Petya applies permutation q (which he has got from his mother) to permutation p.  All actions are similar to point 1, except that Petya writes permutation t on the board, such that: t_{q}_{i} = p_{i} for all i from 1 to n. In other words, Petya applies a permutation that is inverse to q to permutation p. 

We know that after the k-th move the board contained Masha's permutation s_1, s_2, ..., s_{n}. Besides, we know that throughout the game process Masha's permutation never occurred on the board before the k-th move. Note that the game has exactly k moves, that is, throughout the game the coin was tossed exactly k times.

Your task is to determine whether the described situation is possible or else state that Petya was mistaken somewhere. See samples and notes to them for a better understanding.


-----Input-----

The first line contains two integers n and k (1 ≤ n, k ≤ 100). The second line contains n space-separated integers q_1, q_2, ..., q_{n} (1 ≤ q_{i} ≤ n) — the permutation that Petya's got as a present. The third line contains Masha's permutation s, in the similar format.

It is guaranteed that the given sequences q and s are correct permutations.


-----Output-----

If the situation that is described in the statement is possible, print "YES" (without the quotes), otherwise print "NO" (without the quotes).


-----Examples-----
Input
4 1
2 3 4 1
1 2 3 4

Output
NO

Input
4 1
4 3 1 2
3 4 2 1

Output
YES

Input
4 3
4 3 1 2
3 4 2 1

Output
YES

Input
4 2
4 3 1 2
2 1 4 3

Output
YES

Input
4 1
4 3 1 2
2 1 4 3

Output
NO



-----Note-----

In the first sample Masha's permutation coincides with the permutation that was written on the board before the beginning of the game. Consequently, that violates the condition that Masha's permutation never occurred on the board before k moves were performed.

In the second sample the described situation is possible, in case if after we toss a coin, we get tails.

In the third sample the possible coin tossing sequence is: heads-tails-tails.

In the fourth sample the possible coin tossing sequence is: heads-heads.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Mathematics

Implementation


Solutions:
(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
ups = [[i + 1 for i in range(n)]]
downs = [[i + 1 for i in range(n)]]

def apply(arr):
	out = [0] * n
	for i in range(n):
		out[i] = arr[a[i] - 1]
	return out

def unapply(arr):
	out = [0] * n
	for i in range(n):
		out[a[i] - 1] = arr[i]
	return out
for i in range(k):
	ups.append(apply(ups[i]))
for i in range(k):
	downs.append(unapply(downs[i]))
earliest = [None, None]
earliestPossible = [None, None]
for i in range(k, -1, -1):
	if ups[i] == b:
		earliest[0] = i
	if downs[i] == b:
		earliest[1] = i
for i in range(k, -1, -2):
	if ups[i] == b:
		earliestPossible[0] = i
	if downs[i] == b:
		earliestPossible[1] = i
if not earliestPossible[0] and (not earliestPossible[1]):
	print('NO')
	exit(0)
if (not earliestPossible[0] or earliest[0] < earliestPossible[0]) and (not earliestPossible[1] or earliest[1] < earliestPossible[1]):
	print('NO')
	exit(0)
if ups[0] == b or (ups[1] == b and downs[1] == b and (k > 1)):
	print('NO')
	exit(0)
print('YES')


def Solve(x, L):
	if x == k[0]:
		return L == S
	if (x, tuple(L)) in Mem:
		return False
	if L == S:
		return False
	E = []
	for i in range(len(L)):
		E.append(L[Q[i] - 1])
	if Solve(x + 1, E):
		return True
	E = [0] * len(L)
	for i in range(len(L)):
		E[Q[i] - 1] = L[i]
	if Solve(x + 1, E):
		return True
	Mem[x, tuple(L)] = 1
	return False
Mem = {}
k = [0]
(n, k[0]) = map(int, input().split())
P = list(range(1, n + 1))
Q = list(map(int, input().split()))
S = list(map(int, input().split()))
if Solve(0, P):
	print('YES')
else:
	print('NO')


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))
(n, k) = mints()
q = list(mints())
for i in range(n):
	q[i] -= 1
s = list(mints())
a = [i for i in range(1, n + 1)]
d = [0] * n
b = [False] * (k + 1)
c = [False] * (k + 1)
e = [10000] * 2
f = [10000] * 2
for i in range(k + 1):
	b[i] = a == s
	if b[i]:
		e[i % 2] = min(e[i % 2], i)
	for j in range(n):
		d[j] = a[q[j]]
	(a, d) = (d, a)
a = [i for i in range(1, n + 1)]
for i in range(k + 1):
	c[i] = a == s
	if c[i]:
		f[i % 2] = min(f[i % 2], i)
	for j in range(n):
		d[q[j]] = a[j]
	(a, d) = (d, a)
if e[0] == 0:
	print('NO')
elif e[1] == 1:
	if f[1] == 1 and k > 1:
		print('NO')
	elif k % 2 == 1 or f[k % 2] <= k:
		print('YES')
	else:
		print('NO')
elif f[1] == 1:
	if k % 2 == 1 or e[k % 2] <= k:
		print('YES')
	else:
		print('NO')
elif e[k % 2] <= k or f[k % 2] <= k:
	print('YES')
else:
	print('NO')