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++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define mp make_pair

void print(auto &a)
{
    for (auto s: a) cout<<s<<' ';
    cout<<endl;
}

void get(vector<auto> &a)
{
    for (int i = 0; i<a.size(); i++) cin>>a[i];
}

const int p =  1e9 + 7;


int mul(int a, int b) {
    return (1LL * a%p * b%p) % p;
}

int add(int a, int b) {
    ll s = (a+b);
    s = s%p;
    if (s<0) s+=p; 
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}



vector<int> Z(string s)
{
int n = s.length();
vector<int> z(n);
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
  if (i > R) {
    L = R = i;
    while (R < n && s[R-L] == s[R]) R++;
    z[i] = R-L; R--;
  } else {
    int k = i-L;
    if (z[k] < R-i+1) z[i] = z[k];
    else {
      L = i;
      while (R < n && s[R-L] == s[R]) R++;
      z[i] = R-L; R--;
    }
  }
}
return z;
}

vector<int> opvec(vector<int> a, vector<int> b)
{
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[a[i]] = b[i];
    return res;
}

vector<int> invvec(vector<int> a)
{
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[a[i]] = i;
    return res;
}

vector<int> mulvec(vector<int> a, vector<int> b)
{
    a = invvec(a);
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[a[i]] = b[i];
    return res;
}

vector<int> id(int n)
{
    vector<int> res(n);
    for (int i = 0; i<n; i++) res[i] = i;
    return res;
}

vector<int> power(vector<int> a, int deg)
{
    if (deg==0) return id(a.size());
    if (deg%2==1) return mulvec(power(a, deg-1), a);
    auto kek = power(a, deg/2);
    return mulvec(kek, kek);
}



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, k;
    cin>>n>>k;
    vector<int> a(n), b(n);
    get(a);
    get(b);
    for (int i = 0; i<n; i++) {a[i]--; b[i]--;}
    vector<int> keks(n);
    
    int m = 0;
    if (k>21) m = (k-20)/6;
    keks = mulvec(opvec(b, a), b);
    keks = mulvec(keks, invvec(a));
    keks = power(keks, m);
    k -= 6*m;
    vector<vector<int>> operations(k);
    operations[0] = a;
    operations[1] = b;
    for (int i = 2; i<k; i++) operations[i] = opvec(operations[i-2], operations[i-1]);
    vector<int> answer = mulvec(keks, operations[k-1]);
    answer = mulvec(answer, invvec(keks));
    for (int i = 0; i<n; i++) answer[i]++;
    print(answer);
    
}