Problem:
Score : 1000 points

Problem Statement

For two permutations p and q of the integers from 1 through N, let f(p,q) be the permutation that satisfies the following:

The p_i-th element (1 \leq i \leq N) in f(p,q) is q_i.
Here, p_i and q_i respectively denote the i-th element in p and q.

You are given two permutations p and q of the integers from 1 through N.
We will now define a sequence {a_n} of permutations of the integers from 1 through N, as follows:

a_1=p, a_2=q

a_{n+2}=f(a_n,a_{n+1}) ( n \geq 1 )

Given a positive integer K, find a_K.

Constraints

1 \leq N \leq 10^5

1 \leq K \leq 10^9

p and q are permutations of the integers from 1 through N.

Input

Input is given from Standard Input in the following format:

N K
p_1 ... p_N
q_1 ... q_N

Output

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

Sample Input 1

3 3
1 2 3
3 2 1

Sample Output 1

3 2 1

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

Sample Input 2

5 5
4 5 1 2 3
3 2 1 5 4

Sample Output 2

4 3 2 1 5

Sample Input 3

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

Sample Output 3

7 9 4 8 2 5 1 6 10 3

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	static int F => int.Parse(Str);
	static long FL => long.Parse(Str);
	static int[] G => Strs.Select(int.Parse).ToArray();
	static decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	static long[] GL => Strs.Select(long.Parse).ToArray();
	static string Str => ReadLine();
	static string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	static int N;
	void Solve()
	{
		var I = G;
		N = I[0];
		WriteLine(ToString(Calc(Get(), Get(), I[1] - 1)));
	}
	static int[] Get() => G.Select(i => i - 1).ToArray();
	static string ToString(int[] p) => string.Join(" ", p.Select(i => i + 1));
	static int[] Calc(int[] p, int[] q, int K)
	{
		// if (K == 0) return p;
		// if (K == 1) return q;
		// if (K < 6) return Calc(q, Mult(q, Inv(p)), K - 1);
		int[] ip = Inv(p), iq = Inv(q), x = Mult(q, ip, iq, p), y = Mult(ip, q, p, iq);
		switch (K % 6)
		{
			case 0: return Mult(Pow(x, K / 6), q, p, iq, Pow(y, K / 6 - 1));
			case 1: return Mult(Pow(x, K / 6), q, Pow(y, K / 6));
			case 2: return Mult(Pow(x, K / 6), q, ip, Pow(y, K / 6));
			case 3: return Mult(Pow(x, K / 6), q, ip, iq, Pow(y, K / 6));
			case 4: return Mult(Pow(x, K / 6 + 1), iq, Pow(y, K / 6));
			default: return Mult(Pow(x, K / 6 + 1), p, iq, Pow(y, K / 6));
		}
	}
	static int[] Inv(int[] a)
	{
		var c = new int[N];
		for (var i = 0; i < N; i++) c[a[i]] = i;
		return c;
	}
	static int[] Mult(int[] a, int[] b)
	{
		var c = new int[N];
		for (var i = 0; i < N; i++) c[i] = a[b[i]];
		return c;
	}
	static int[] Mult(params int[][] a)
	{
		if (a.Length == 0) return MakeArray(N, i => i);
		var x = a[0];
		for (var i = 1; i < a.Length; i++) x = Mult(x, a[i]);
		return x;
	}
	static int[] Pow(int[] a, int b)
	{
		var p = new int[N];
		var done = new bool[N];
		for (var i = 0; i < N; i++)
			if (!done[i])
			{
				done[i] = true;
				var cycle = new List<int> { i };
				var x = a[i];
				while (x != i) { cycle.Add(x); done[x] = true; x = a[x]; }
				var L = cycle.Count;
				var c = (b + L) % L;
				for (var j = 0; j < L; j++) p[cycle[j]] = cycle[(j + c) % L];
			}
		return p;
	}
}