15025 - RedCapeFlyingCat Plays on the Grass   

Description

Story

A new semester has begun, and everyone must have missed RedCapeFlyingCat! RedCapeFlyingCat wants to play a game with all the students taking Data Structures (that is, you, a penguin).

Problem Statement

people stand in a circle, numbered clockwise. Person holds a flag.

Passing the flag one step means giving it to the next person clockwise.

Process operations:

  • insert(k, id): Pass the flag steps. Then add a new person right after the holder (clockwise). The new person takes the flag.
  • erase(k): Pass the flag steps. Then pass it more step, and remove the person who just gave it away. Output the removed person.
  • print(): Output everyone in the circle, clockwise, starting from the holder.

Explanation

insert/erase/print operations illustration

The circle is listed clockwise. The flag holder is in bold.

Initially: .

  1. insert(2, 17): The flag moves . Person is added after and takes the flag. Circle: .
  2. erase(3): The flag moves , then one more step to . Person is removed, so output 1. Circle: .
  3. print(): Output 2 3 17 4 5.

Input

The first line contains two integers and — the initial number of people and the number of operations.

Each of the next lines describes one operation in one of the following formats:

  • insert k id
  • erase k
  • print

Constraints

  • in every operation, and the sum of all is at most
  • Every inserted satisfies , and all inserted are distinct
  • Before each erase, the circle has at least people
  • All print() operations output at most numbers in total

Subtasks

Subtask Constraints Operations
1 , insert, erase
2 , insert, erase, print
3~6 No additional constraints insert, erase, print

Output

For each erase operation, output one line: the number of the removed person.

For each print operation, output one line: the numbers of everyone in the circle, space-separated, clockwise, starting from the flag holder.

Output the lines in the order of the operations.

Sample Input  Download

Sample Output  Download

Tags




Discuss