Playing with Permutations

Little Petya likes permutations a lot. Recently his mom has presented him permutation q 1, q 2, …, q n of length n.

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.
    1. 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.
    2. 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.

Solution:

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>

using namespace std;

const int N = 11111;

int n, k, i, z;
int a[N], q[N], v[N], b[N], s[N];

int main() {
//  freopen("in", "r", stdin);
//  freopen("out", "w", stdout);
scanf("%d %d", &n, &k);
for (i=1;i<=n;i++) scanf("%d", q+i);
  for (i=1;i<=n;i++) v[q[i]] = i;
  for (i=1;i<=n;i++) scanf("%d", s+i);
  int left = -k-1, right = k+1;
  for (i=1;i<=n;i++) a[i] = i;
  for (z=0;z<=k;z++) {
    int ok = 1;
    for (i=1;i<=n;i++)
      if (a[i] != s[i]) ok = 0;
    if (ok) {
      right = z;
      break;
    }
    for (i=1;i<=n;i++) b[i] = a[q[i]];
    for (i=1;i<=n;i++) a[i] = b[i];
  }
  for (i=1;i<=n;i++) a[i] = i;
  for (z=0;z>=-k;z--) {
int ok = 1;
for (i=1;i<=n;i++)
      if (a[i] != s[i]) ok = 0;
    if (ok) {
      left = z;
      break;
    }
    for (i=1;i<=n;i++) b[i] = a[v[i]];
    for (i=1;i<=n;i++) a[i] = b[i];
  }
  if (left == 0 && right == 0) puts("NO"); else
  if (k == 1 && (left == -1 || right == 1)) puts("YES"); else
  if (left == -1 && right == 1) puts("NO"); else
  if ((k+left) % 2 == 0 || (k-right) % 2 == 0) puts("YES");
  else puts("NO");
  return 0;
}