Madoka and Homura are two mahou shoujos (magical girls) who know a lot about magician tricks.
Today, Madoka brought $2N$ cards and challenged Homura for a game. The cards are numbered from $1$ to $2N$ in ascending order, that is the order of the deck of card is $[1, 2, 3, ..., 2N]$.
As a good magical girl, Madoka can perform faro in-shuffle and faro out-shuffle perfectly. Suppose the original order of a deck of card is $[S_1, S_2, S_3, ... S_{2N}]$, the order of cards will become $[S_{N+1}, S_1, S_{N+2}, S_2 ... S_{2N}, S_N]$ after performing a faro in-shuffle. Similarly, the order of cards will become $[S_1, S_{N+1}, S_2, S_{N+2} ... S_N, S_{2N}]$ after performing a faro out-shuffle.
Now Madoka will perform $M$ shuffles on the deck of cards. The first shuffle will be faro in-shuffle, the second shuffle will be faro out-shuffle, the third shuffle will be faro in-shuffle again, and so on. Formally, the $i^{th}$ shuffle will be a faro in-shuffle if $i$ is an odd number, otherwise it will be a faro out-shuffle.
After shuffling, Madoka asked Homura to tell her the final order of the cards. Since Homura is also a good magical girl, she immediately solved the challenge. To check the correctness of her answer and check whether Madoka cheated, they asked you to tell them the correct order.
Input
The first line of input contains two integers, $N$ and $M$.
Output
Output $2N$ integers, seperated by space, the final order of cards after shuffling.
Constraints
For all cases, $1 \le N \le 5\times10^5, 0 \le M \le 10^9$
Subtask 1 (15%): $0 \le M \le 2$
Subtask 2 (15%): $N \times M \le 5\times10^6$
Subtask 3 (40%): $1 \le N \le 5000$
Subtask 4 (30%): No additional constraints
Sample Test Cases
Input | Output | |
---|---|---|
3 0 | 1 2 3 4 5 6 | |
3 1 | 4 1 5 2 6 3 | |
4 8 | 4 2 8 6 3 1 7 5 |
Scoring: Per Subtask
Authored by wy23493
Appeared in 2023 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆