Under construction

Still being built. Things may change

The Case of the Game

Interview

Time limit2sMemory limit1024 MB

Summary
Track the ammo count through save, load, shoot, and ammo actions, and print the count after each action.
Level

Easy2 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

Sherlock: You killed a man.

John: I know. It is certain. But he was not an important man.

John Watson has psychosomatic pain in his leg, so his personal psychiatrist advised him to play shooter games. Watson is an excellent shot, but he struggles with mental tasks. He cannot remember how many rounds he has left.

In the game, you can save, load the last save, pick up a crate of kk rounds, and shoot one round. After a load, the ammo count becomes the same as it was at the last save. If a load happens before the first save, the ammo count becomes zero.

After each action by John, report how many rounds he has at that moment. Initially he has zero rounds. It is guaranteed that Watson never shoots when he has no ammo.

Input

The first line contains two integers nn and kk (1≤n≤1001 \le n \le 100, 1≤k≤1001 \le k \le 100), where nn is the number of John's actions and kk is the number of rounds in one crate. Each of the next nn lines contains aia_i, which is one of the following:

  • save: save the game
  • load: load the last save
  • shoot: shoot one round
  • ammo: pick up a crate with kk rounds

Output

For each action, print the number of rounds Watson has left after that action.

Hint

The first test group is checked when the solution is submitted and is worth 50 points. Points for this group are awarded only if all tests in the group pass. No test in this group contains save or load commands.

The second test group is checked after the olympiad ends and is worth 50 points. Points for this group are awarded only if all tests in the group pass.

Examples1

  1. Example 1

    Input
    7 3
    ammo
    save
    shoot
    ammo
    load
    shoot
    load
    
    Expected output
    3
    3
    2
    5
    3
    2
    3