#2177. 牛舞蹈shuffles [USACO17DEC] The Bovine Shuffle B

牛舞蹈shuffles [USACO17DEC] The Bovine Shuffle B

Description

原文:

Convinced that happy cows generate more milk, Farmer John has installed a giant disco ball in his barn and plans to teach his cows to dance!

Looking up popular cow dances, Farmer John decides to teach his cows the "Bovine Shuffle". The Bovine Shuffle consists of his N cows (1≤N≤100) lining up in a row in some order, then performing three "shuffles" in a row, after which they will be lined up in some possibly different order. To make it easier for his cows to locate themselves, Farmer John marks the locations for his line of cows with positions 1…N, so the first cow in the lineup will be in position 1, the next in position 2, and so on, up to position N.

A shuffle is described with N numbers,a1aNa_1​…a_N​, where the cow in position 𝑖i moves to position 𝑎𝑖ai​ during the shuffle (and so, each 𝑎𝑖ai​ is in the range 1…N). Every cow moves to its new location during the shuffle. Fortunately, all the 𝑎𝑖′𝑠ai′​s are distinct, so no two cows try to move to the same position during a shuffle.

Farmer John's cows are each assigned distinct 7-digit integer ID numbers. If you are given the ordering of the cows after three shuffles, please determine their initial order.

翻译:

FJ深信,快乐的奶牛会产生更多的牛奶,他在谷仓里安装了一个巨大的迪斯科球,并计划教他的奶牛跳舞。

他研究了时下流行的牛舞蹈,最终决定教他的牛跳“牛步舞” ("Bovine Shuffle")。牛步舞需要他的𝑁N头牛(1≤N≤100)按某种顺序排成一排,然后连续进行三次 "shuffles",之后它们将按某种可能不同的顺序排成一排。为了让奶牛更容易找到自己的位置,FJ用1...N的位置来标记他的奶牛在队列中的位置,所以队列中的第一头奶牛将在位置1,下一个在位置2,以此类推,直到位置N。

一次"shuffle"用N个数字描述,a1...aNa_1​...a_N​,其中位置i的奶牛在shuffle期间移动到位置𝑎𝑖ai​(因此,每个𝑎𝑖ai​在1...N的范围内)。在shuffle的过程中,每头牛都会移动到它的新位置。幸运的是,所有的𝑎𝑖ai​都是不同的。因此,在shuffle过程中没有两头奶牛试图移动到同一个位置。

FJ的奶牛都被分配了不同的7位数整数ID。给出三次shuffle后奶牛的顺序,请确定它们的初始顺序。

Format

Input

第一行输入包含N,牛的数量。下一行包含N个整数a1aNa_1​…a_N​。最后一行包含三次洗牌后N头牛的顺序,每头牛都由其ID编号指定。

Output

你需要输出N行,每行都有一头牛的ID。这些ID将表示牛在三次shuffle之前的顺序。

Samples

5
1 3 4 5 2
1234567 2222222 3333333 4444444 5555555
1234567
5555555
2222222
3333333
4444444