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++ (GCC 9.2.1) (judge verdict: Accepted)

#define DEBUG 1

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int p[100000],q[100000],P[100000],Q[100000];
int R[100000],r[100000];
int n[31][100000];
int ans[100000];
int apply(int *ans,int *perm,int N) {
    int i;
    for (i = 0; i < N; i++) ans[i] = perm[ans[i]];
    return 0;
}
int a[10][100000];
int main() {
    int i,j;
    int N,K;
    scanf("%d %d",&N,&K),K--;
    for (i = 0; i < N; i++) scanf("%d",&p[i]),p[i]--,P[p[i]] = i;
    for (i = 0; i < N; i++) scanf("%d",&q[i]),q[i]--,Q[q[i]] = i;
    if (K < 10) {
        for (i = 0; i < N; i++) a[0][i] = p[i],a[1][i] = q[i];
        for (i = 2; i <= K; i++) {
            for (j = 0; j < N; j++) a[i][a[i-2][j]] = a[i-1][j];
        }
        for (i = 0; i < N; i++) printf("%d ",a[K][i]+1);
        printf("\n");
        return 0;
    }

    for (i = 0; i < N; i++) ans[i] = i,R[i] = i,r[i] = i;
    apply(ans,Q,N);
    apply(R,p,N),apply(R,q,N),apply(R,P,N),apply(R,Q,N);
    int c = (K-3)/6;
    for (i = 0; i < N; i++) n[0][i] = R[i];
    for (i = 1; i <= 30; i++) {
        for (j = 0; j < N; j++) n[i][j] = n[i-1][n[i-1][j]];
    }
    for (i = 0; i < N; i++) {
        for (j = 30; j >= 0; j--) {
            if (c & (1 << j)) ans[i] = n[j][ans[i]];
        }
    }
    c = K % 6;
    if (c == 0) apply(ans,p,N);
    else if (c == 1) apply(ans,p,N),apply(ans,q,N),apply(ans,P,N);
    else if (c == 2) apply(ans,p,N),apply(ans,q,N),apply(ans,P,N),apply(ans,P,N);
    else if (c == 3) apply(ans,P,N);
    else if (c == 4) apply(ans,p,N),apply(ans,Q,N),apply(ans,P,N);
    else if (c == 5) apply(ans,p,N),apply(ans,p,N),apply(ans,Q,N),apply(ans,P,N);
    c = K/6;
    apply(r,q,N),apply(r,p,N),apply(r,Q,N),apply(r,P,N);
    for (i = 0; i < N; i++) n[0][i] = r[i];
    for (i = 1; i <= 30; i++) {
        for (j = 0; j < N; j++) n[i][j] = n[i-1][n[i-1][j]];
    }
    for (i = 0; i < N; i++) {
        for (j = 30; j >= 0; j--) {
            if (c & (1 << j)) ans[i] = n[j][ans[i]];
        }
    }
    apply(ans,q,N);
    for (i = 0; i < N; i++) printf("%d ",ans[i]+1);
    printf("\n");
    
    return 0;
}