P27187 [AtCoder] Card Shuffling
提高
题目描述

Problem Description

There are $2n$ cards with numbers from $1$ to $2n$ written on them, stacked in the order $1, 2, 3, \ldots, 2n$ from top to bottom.

These cards are to be rearranged using the following methods several times.

Cut with integer $k$

Divide the cards into two piles, A and B, where A consists of the top $k$ cards and B consists of the remaining cards. Then, place pile B on top of pile A.

card01.png

Riffle Shuffle

Divide the cards into two piles, A and B, where A consists of the top $n$ cards and B consists of the remaining cards. Then, combine them into one pile in the order: the top card of A, the top card of B, the second card of A, the second card of B, $\ldots$, the $n$th card of A, the $n$th card of B.

card02.png

Write a program that, following the input instructions, outputs the numbers of the cards after rearrangement, from top to bottom.


Input Format

  • The first line contains $n$ ($1 \leq n \leq 100$), meaning there are $2n$ cards.
  • The second line contains the number of operations $m$ ($1 \leq m \leq 1000$).
  • The next $m$ lines from the third to the $m + 2$th line each contain an integer $k$ from $0$ to $2n - 1$, specifying the method to rearrange the cards in order.
  • If $k = 0$, perform a riffle shuffle.
  • If $1 \leq k \leq 2n - 1$, perform a cut with $k$.

Output Format

Output $2n$ lines. The first line should contain the number of the top card after rearrangement, the second line should contain the number of the second card from the top, and so on. The $i$th line should contain the number of the $i$th card from the top.


Sample Input and Output

Sample Input #1

2
2
1
0

Sample Output #1

2
4
3
1

Sample Input #2

3
4
2
4
0
0

Sample Output #2

1
5
4
3
2
6

Notes/Hints

Sample Explanation 1

- - - - - -

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 1 0
样例输出
2 4 3 1