atcoder#AGC031D. [AGC031D] A Sequence of Permutations
[AGC031D] A Sequence of Permutations
Score : points
Problem Statement
For two permutations and of the integers from through , let be the permutation that satisfies the following:
- The -th element () in is . Here, and respectively denote the -th element in and .
You are given two permutations and of the integers from through . We will now define a sequence {} of permutations of the integers from through , as follows:
- ,
- ( )
Given a positive integer , find .
Constraints
- and are permutations of the integers from through .
Input
Input is given from Standard Input in the following format:
Output
Print integers, with spaces in between. The -th integer () should be the -th element in .
3 3
1 2 3
3 2 1
3 2 1
Since , we just need to find . We have here, so .
5 5
4 5 1 2 3
3 2 1 5 4
4 3 2 1 5
10 1000000000
7 10 6 5 4 2 9 1 3 8
4 1 9 2 3 7 8 10 6 5
7 9 4 8 2 5 1 6 10 3