Hide

Problem K
Riffle Shuffle

/problems/riffleshuffle/file/statement/en/img-0001.png
Image by Wikimedia Commons

One technique often used to shuffle a deck of cards is called the riffle shuffle, where the person shuffling will split the deck into top and bottom halves, and then alternate both halves card by card by starting with the top card of the bottom half, and then alternating each card from both halves until the cards are fully shuffled.

Assume that a deck consisting of $n$ cards is labeled $1$ through $n$, where the top card is $1$ and the bottom card is $n$, initially. Then, the deck will be perfectly riffle-shuffled $k$ times. If $n$ is odd, the bottom half will have the extra card.

What order will the deck be in after $k$ riffle shuffles?

Input

The input consists of a single line containing two integers, $n$ and $k$ ($2 \le n \le 100$, $1 \le k \le 2^{63} - 1$), where $n$ is the number of cards in the deck and $k$ is the number of riffle shuffles.

Output

Print $n$ integers separated by single spaces that describe the labels of the cards in the stack, from top to bottom, in the order that would result from applying $k$ riffle shuffles to a sorted deck.

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

Please log in to submit a solution to this problem

Log in