Polish version    English version  
  About Olympic -> Problems -> X OI 2002/2003


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
X Olympiad in Informatics 2002/2003

Problem: Shuffle
Author: Pawel Parys

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 <= k <= 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 (bk),
  • determines the sequence of numbers (ak),
  • 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 <= nl <= 1000000). In the consecutive n lines there are successive elements of the sequence (bk), one per line. In the (k + 1)-st line there is a positive integer bk: the final position of the card from the k-th position, 1 <= bk <= n.

Output

Your program should write to the standard output n integers: successive elements of the sequence (ak), one per line. In the k-th line there should be one number ak: 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 (ak). If there are many such sequences your program should write one of them (arbitrary).

Example

For the following input data:
5 2
1
2
5
3
4
a correct answer is in the following output:
1
2
4
5
3
or:
2
1
4
5
3



Print friendly version