QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#14185. Shuffle

统计

Byteasar has a pack of $n$ cards that he likes to shuffle. The positions of cards are numbered from $1$ to $n$. Byteasar has acquired such a skill in shuffling that each time he obtains the same arrangement, i.e. a card from the $k$-th position ($1 \le k \le n$) always goes to the same ak-th position. We denote by bk the position of the $k$-th card (i.e. the card initially placed at the $k$-th position) after Byteasar repeated shuffling $l$ times.

Task

Write a program which:

  • reads from the standard input the numbers $n$ and $l$ and the sequence of numbers ,($b_k$)
  • determines the sequence of numbers ($a_k$),
  • writes that sequence to the standard output.

Input

In the first line of the standard input there are two positive integers $n$ and $l$ ($1 \le n, l \le 1\,000\,000$). In the consecutive $n$ lines there are successive elements of the sequence ($b_k$), one per line. In the $(k+1)$-st line there is a positive integer $b_k$: the final position of the card from the $k$-th position, $1 \le b_k \le n$.

Output

Your program should write to the standard output $n$ integers: successive elements of the sequence ($a_k$), one per line. In the $k$-th line there should be one number $a_k$: the position of the card from the $k$-th position after a single shuffle. You may assume that for the test data there always exist the desired sequence ($a_k$). If there are many such sequences your program should write one of them (arbitrary).

Example

Input

5 2
1
2
5
3
4

Output

1
2
4
5
3

Input 2

5 2
1
2
5
3
4

Output 2

2
1
4
5
3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.