This page is still under construction.

Parts of this page are still being built. What you see may change.

Do the Shuffle

Interview

Time limit1sMemory limit128 MB

Summary
Simulate a fixed 5-song playlist through button presses that rotate left, rotate right, or swap the first two songs, then print the final order.
Level

Easy2 of 10

Topics
Simulation, Implementation, Array
Solved
No attempts yet

Problem

Those tiny music machines that play digital music are really small computers that store and play music files. A new portable music player called the C3MP is in development and will hit stores soon. In this problem you have to simulate a C3MP.

The C3MP holds 5 songs in memory, whose titles are always “A”, “B”, “C”, “D” and “E”. It also keeps a playlist, which is an ordering of all the songs. The player has 4 buttons that rearrange the playlist and play the songs.

Initially the playlist is A, B, C, D, E. The 4 buttons do the following:

  • Button 1: move the first song of the playlist to the end. For example, A, B, C, D, E becomes B, C, D, E, A.
  • Button 2: move the last song of the playlist to the start. For example, A, B, C, D, E becomes E, A, B, C, D.
  • Button 3: swap the first two songs of the playlist. For example, A, B, C, D, E becomes B, A, C, D, E.
  • Button 4: stop rearranging and output the playlist.

Input

The input is a sequence of button presses. Each press is given as two positive integers bb and nn: bb is the button number (1≤b≤41 \le b \le 4) and nn is the number of times to press button bb (1≤n≤101 \le n \le 10). The two integers of a press may be separated by spaces or newlines.

The input always ends with the press b=4b = 4, n=1n = 1. When you read it, print the current playlist and stop. Button 4 is pressed exactly once, at the very end.

Output

Print the titles of the songs in the final playlist order, on one line, separated by single spaces.

Examples5

  1. Example 1

    Input
    2
    1
    3
    1
    2
    3
    4
    1
    
    Expected output
    B C D A E
    
  2. Example 2

    Input
    4
    1
    
    Expected output
    A B C D E
    
  3. Example 3

    Input
    1
    1
    4
    1
    
    Expected output
    B C D E A
    
  4. Example 4

    Input
    2
    1
    4
    1
    
    Expected output
    E A B C D
    
  5. Example 5

    Input
    3
    1
    4
    1
    
    Expected output
    B A C D E