Under construction

Still being built. Things may change

The Bovine Shuffle

Interview

Time limit2sMemory limit512 MB

Summary
Given a permutation describing one shuffle and the cow order after three shuffles, recover the original order before the shuffles.
Level

Medium4 of 10

Topics
Array, Implementation, Simulation, Math
Solved
No attempts yet

Problem

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

After looking up popular cow dances, Farmer John settled on the Bovine Shuffle. In the Bovine Shuffle his NN cows (1≤N≤1001 \le N \le 100) line up in a row in some order and then perform three shuffles in a row, after which they stand in a possibly different order. To make it easier for the cows to locate themselves, Farmer John numbered the spots in the line 11 through NN, so the first cow in the lineup stands at position 11, the next at position 22, and the last at position NN.

One shuffle is described by NN numbers a1,…,aNa_1, \ldots, a_N. During the shuffle the cow at position ii moves to position aia_i, and every aia_i is between 11 and NN. Every cow moves to its assigned position during the shuffle. All of the aia_i are distinct, so no two cows ever try to move to the same position.

Each of Farmer John's cows carries a 7-digit integer ID, and no two cows share an ID. Given the order of the cows after the three shuffles, determine the order they started in.

Input

The first line contains NN, the number of cows. The second line contains the NN integers a1,…,aNa_1, \ldots, a_N. The third line contains the order of the NN cows after three shuffles, with each cow given by its ID.

Output

Print NN lines giving the order of the cows before the three shuffles, one cow ID per line.

Examples4

  1. Example 1

    Input
    5
    1 3 4 5 2
    1234567 2222222 3333333 4444444 5555555
    
    Expected output
    1234567
    5555555
    2222222
    3333333
    4444444
    
  2. Example 2

    Input
    1
    1
    1000000
    
    Expected output
    1000000
    
  3. Example 3

    Input
    2
    2 1
    1234567 7654321
    
    Expected output
    7654321
    1234567
    
  4. Example 4

    Input
    4
    1 2 3 4
    1111111 2222222 3333333 4444444
    
    Expected output
    1111111
    2222222
    3333333
    4444444