Hide

Problem H
Dans

Languages en is

When Forritunarkeppni Framhaldsskólanna was held in the 19th century the traditions were different than today. For example all candy was considered evil. The contest was held along with Þorrablót and contestants ate Þorramatur while the contest was ongoing, each bite of shark being counted as a point for the team in question. Thus there were some years (1867, 1897, 1899) where the winning team won just by eating inordinate amounts of shark.

One tradition that got lost throughout the years was the formal dance of Forritunarkeppni Framhaldsskólanna. That dance was one of the most respected events of the country and was coordinated by Hallgrímur back then. Hallgrímur enjoyed simple dance forms, especially vikivaki. Vikivaki is a dance where the contestants join hands in a circle and take specific steps to the beat of the music, though Hallgrímur liked to add some complications to the dance. After each chorus in the song being danced to, Hallgrímur makes some of the participants move to a new place in the circle.

These changes Hallgrímur makes on the positions of the participants can be described by, for each position $i$ in the circle, giving the person that should be there after the chorus. For example, let us say that Hallgrímur decides that the person in location $3$ should go to position $1$, person at position $1$ should go to position $2$ and the person in position $2$ should go to position $3$, then this would be denoted $3~ 1~ 2$.

Hallgrímur has decided to hold the dance again this year and wants to know, for some rearrangement description, where each contestant will be after exactly $k$ choruses. Like usual, it’s easier to call some programmer over to make a program that solves this than to do it himself, so you have been tasked with this job!

Input

The input contains exactly two lines. The first contains two integers $N$ and $K$ and the second consists of $N$ integers $\pi _1 \pi _2 \dotsc \pi _N$. There the $i$-th number, $\pi _i$, denotes that the person at location $\pi _i$ should be at position $i$ in the circle after the next chorus. This second line only contains values from $1$ to $N$ and each number appears only once.

Output

Print a single line containing $N$ numbers, $\rho _1 \rho _2 \dotsc \rho _N$ separated by spaces, denoting that the person who started at position $\rho _i$ ended in position $i$ after $K$ choruses.

Explanation of Sample Inputs

In the first sample there are three people in the circle and two choruses are danced to. After the first chorus the person in location $3$ moved to $1$, the person in location $2$ moved to $1$, and $1$ to $3$. After the second chorus the persin now in location $2$ (originally in $3$) moves to $1$, the person in location $3$ (originally $1$) moves to $2$ and the person at location $1$ (originally $2$) moves to $3$. Thus the output is $3~ 1~ 2$.

\includegraphics[width=0.6\textwidth ]{figures/fig1.pdf}

A similar image as for the first sample can be seen here below for the third sample.

\includegraphics[width=0.6\textwidth ]{figures/fig2.pdf}

Scoring

Group

Points

Constraints

1

10

$1 \leq N \leq 2,\, 0 \leq K \leq 10$

2

40

$1 \leq N \leq 10,\, 0 \leq K \leq 10$

3

25

$1 \leq N \leq 2,\, 0 \leq K \leq 10^9$

4

25

$1 \leq N \leq 1\, 000,\, 0 \leq K \leq 10^9$

Sample Input 1 Sample Output 1
3 2
2 3 1
3 1 2
Sample Input 2 Sample Output 2
2 3
1 2
1 2
Sample Input 3 Sample Output 3
5 2
3 5 4 1 2
4 2 1 3 5

Please log in to submit a solution to this problem

Log in