atcoder#AGC031D. [AGC031D] A Sequence of Permutations

[AGC031D] A Sequence of Permutations

Score : 10001000 points

Problem Statement

For two permutations pp and qq of the integers from 11 through NN, let f(p,q)f(p,q) be the permutation that satisfies the following:

  • The pip_i-th element (1iN1 \leq i \leq N) in f(p,q)f(p,q) is qiq_i. Here, pip_i and qiq_i respectively denote the ii-th element in pp and qq.

You are given two permutations pp and qq of the integers from 11 through NN. We will now define a sequence {ana_n} of permutations of the integers from 11 through NN, as follows:

  • a1=pa_1=p, a2=qa_2=q
  • an+2=f(an,an+1)a_{n+2}=f(a_n,a_{n+1}) ( n1n \geq 1 )

Given a positive integer KK, find aKa_K.

Constraints

  • 1N1051 \leq N \leq 10^5
  • 1K1091 \leq K \leq 10^9
  • pp and qq are permutations of the integers from 11 through NN.

Input

Input is given from Standard Input in the following format:

NN KK

p1p_1 ...... pNp_N

q1q_1 ...... qNq_N

Output

Print NN integers, with spaces in between. The ii-th integer (1iN1 \leq i \leq N) should be the ii-th element in aKa_K.

3 3
1 2 3
3 2 1
3 2 1

Since a3=f(p,q)a_3=f(p,q), we just need to find f(p,q)f(p,q). We have pi=ip_i=i here, so f(p,q)=qf(p,q)=q.

5 5
4 5 1 2 3
3 2 1 5 4
4 3 2 1 5
10 1000000000
7 10 6 5 4 2 9 1 3 8
4 1 9 2 3 7 8 10 6 5
7 9 4 8 2 5 1 6 10 3