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: Accepted)

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ",debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os,pair<T,S>a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}

//char inv(char c){
//    return c^32;
//}
//string inv(string &a){
//    auto res = a;
//    for(auto &x:res) x^=32;
//    reverse(res.begin(),res.end());
//    return res;
//}
//string product(const string &a,const string &b){
//    auto res = a;
//    for(auto x:b){
//        if(res.size() and inv(x) == res.back())res.erase(res.begin()+res.size()-1);
//        else res.push_back(x);
//    }
//    return res;
//    
//}

vector<int> id(const int n){
    vector<int> res(n);
    rep(i,n)res[i] = i;
    return res;
}
vector<int> inv(const vector<int> &a){
    vector<int> res(a.size());
    rep(i,a.size()){
        res[a[i]] = i;
    }
    return res;
}
vector<int> product(const vector<int> &a, const vector<int> &b){
    vector<int> res(a.size());
    rep(i,a.size()){
        res[i] = a[b[i]];
    }
    return res;
}
vector<int> power(const vector<int> &a, ll p){
    if(p == 0)return id((int)a.size());
    auto res = a;
    auto temp = a;
    p--;
    for(int i = 0; i < 60; i++){
        if(p >> i & 1){
            res = product(res, temp);
        }
        temp = product(temp, temp);
    }
    return res;
}
int main(){
    int n;
    cin >> n;
    int k;
    cin >> k;
    vector<int>p(n),q(n);
    rep(i,n)cin >> p[i],p[i]--;
    rep(i,n)cin >> q[i],q[i]--;
    auto g = product(q,product(inv(p),product(inv(q),p)));
    g = power(g,(k-1)/6);
    auto a = product(g,product(p,inv(g)));
    auto b = product(g,product(q,inv(g)));
    int now = 1 + (k-1)/6*6;
    while(now != k){
        auto c = product(b,inv(a));
        a = b;
        b = c;
        now++;
    }
    rep(i,n)cout << a[i] + 1 << " \n"[i==n-1];
}