QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 64 MB 満点: 100

#23759. Card Shuffle

統計

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

These cards are rearranged by applying the following methods several times:

Cut with integer $k$

Divide the deck into pile A of the top $k$ cards and pile B of the remaining $2n-k$ cards, and then place pile B on top of pile A.

problem_23759_23aef3360de866e41647ebc46ea8acfd.png

Riffle shuffle

Divide the deck into pile A of the top $n$ cards and pile B of the remaining $n$ cards, and combine them into $1$ pile so that from the top the cards are: the $1$st card of A, the $1$st card of B, the $2$nd card of A, the $2$nd card of B, $\ldots$, the $n$-th card of A, the $n$-th card of B.

problem_23759_b7a05d9ba29945a1384455aee42f82a0.png

Write a program that rearranges the cards according to the instructions in the input and outputs the numbers on the cards after rearrangement in order from the top.

Input

  • Line $1$ contains $n$ ($1 \le n \le 100$). That is, the number of cards is $2n$.
  • Line $2$ contains the number of operations $m$ ($1 \le m \le 1000$).
  • The $m$ lines from line $3$ to line $m + 2$ each contain $1$ integer $k$ between $0$ and $2n-1$, specifying the methods to rearrange the cards in order:
    • If $k = 0$, perform a riffle shuffle.
    • If $1 \le k \le 2n-1$, perform a cut with $k$.

Output

The output consists of $2n$ lines. On line $1$, output the number of the top card after rearrangement; on line $2$, output the number of the $2$nd card from the top after rearrangement; and so on, outputting the number of the $i$-th card from the top on line $i$.

Examples

Input 1

2
2
1
0

Output 1

2
4
3
1

Input 2

3
4
2
4
0
0

Output 2

1
5
4
3
2
6

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.