Byteasar has a pack of cards that he likes to shuffle. The
positions of cards are numbered from to . Byteasar has
acquired such a skill in shuffling that each time he obtains the same
arrangement, i.e. a card from the -th position () always goes to the same -th position. We denote by
the position of the -th card (i.e. the card initially
placed at the -th position) after Byteasar repeated shuffling
times.
Task
Write a program which:
reads from the standard input the numbers and and
the sequence of numbers ,
determines the sequence of numbers ,
writes that sequence to the standard output.
Input
In the first line of the standard input there are two positive integers
and (, ). In the consecutive lines there are successive
elements of the sequence , one per line. In the ()-st line there is a positive integer : the final position
of the card from the -th position, .
Output
Your program should write to the standard output integers:
successive elements of the sequence , one per line. In the
-th line there should be one number : the position of
the card from the -th position after a single shuffle. You may
assume that for the test data there always exist the desired sequence
. If there are many such sequences your program should write one
of them (arbitrary).
Example
For the input data:
5 2
1
2
5
3
4
the correct result is:
1
2
4
5
3
or:
2
1
4
5
3
Task author: Pawel Parys.
Kontakt
W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem szkopul@fri.edu.pl.
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, odwiedź nasze serwery na Discordzie. Są one moderowane przez społeczność, ale członkowie zespołu wsparcia również aktywnie się tam udzielają.