YOUTUBE - Youtube

N students are bored in computer class so they watch funny video clips on YouTube.

The site contains K popular clips, numbered 1 through K. When a video clip is watched, a list of similar video clips is displayed on the side.

Every student picks a video clip from the main page and starts watching it. After exactly one minute every student gets bored of his or her video clip, so he opens the first video clip from the list of similar clips on the side (even if he already watched that clip).

Write a program that determines for each student which video clip he will be watching during the M-th minute of the class.

Input

The first line contains three integers N, K and M (1 ≤ N, K ≤ 100 000, 1 < M ≤ 1 000 000 000), the numbers of students, video clips and minutes.

The second line contains N integers, each between 1 and K, the indices of video clips the students start watching.

The third line contains K integers, each between 1 and K, the index of the first similar clip for each video clip.

Output

Output N integers, the indices of video clips that students will be watching during the M-th minute.

Example

Input:
4 5 2
1 2 4 3
5 5 1 2 3

Output:
5 5 2 1
Input:
2 6 5
1 6
2 3 4 1 4 5

Output:
1 2

Added by:Stjepan
Date:2011-02-21
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Croatian Nationals 2009

hide comments
2018-05-15 21:11:38
Hint: think like LCA
2013-06-30 15:24:50 orange
don't spam here!!!
2013-06-23 14:46:42 darryl
it can be solved without looking for cycles...
2013-01-15 16:56:02 Archit Mittal
tough one...
2012-06-28 07:27:18 Troy
can be done without using cycles... has an easy implementation, like dat of suffix array...
2012-06-17 18:34:35 MyTh
giving tle with normal logic of finding cycle.. plz help..
2012-06-12 16:00:05 cool_frog
Giving time limit error !!!! Any hints plz ....
2012-01-15 14:26:19 Smit Mehta
6354341 : It is giving a seg fault after 12 judges!! kindly see it.
2011-08-20 17:34:33 a.out
Don't know which test case i'm missing running fine on my pc and it's giving wrong answer.
2011-07-28 18:25:14 Lewin Gan
Note: if you have a 2d array with bounds [x][y], where x > y, you can get a speed up by switching to bounds [y][x]
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.