Those tiny music machines that play your digital music are really computers that keep track of and play music files. The CCC music player (C3MP) is currently in development and will be hitting the stores soon! In this problem, you have to simulate a C3MP.
The C3MP music player will hold 5 songs in memory, whose titles will always be "A", "B", "C", "D" and "E". The C3MP also keeps track of a playlist, which is an ordering of all the songs. The C3MP has 4 buttons that the user will press to rearrange the playlist and play the songs.
Initially, the C3MP playist is "A, B, C, D, E". The 4 control buttons do the following:
- Button 1: move the first song of the playlist to the end of the playlist.
For example: "A, B, C, D, E" will change to "B, C, D, E, A".
- Button 2: move the last song of the playlist to the start of the playlist.
For example, "A, B, C, D, E" will change to "E, A, B, C, D".
- Button 3: swap the first two songs of the playlist.
For example, "A, B, C, D, E" will change to "B, A, C, D, E".
- Button 4: stop rearranging songs and output the playlist.
You need to write a program to simulate a CCC music player. Your program should repeatedly ask for two positive integers and . Here represents the button number that the user wants to press, , and n represents the number of times that the user wants to press button . You can assume that always satisfies .
The input will always finish with the pair of inputs (, ) when this happens, you should print the order of songs in the current playlist and your program should end. You can assume that the user will only ever press button 4 once.
2 1 3 1 2 3 4 1
Output for Sample Input
B C D A E
- (initial playlist is "A, B, C, D, E")
- (, so "A, B, C, D, E" changed to "E, A, B, C, D")
- (, , so "E, A, B, C, D" changed to "A, E, B, C, D")
- (, , so "A, E, B, C, D" changed to "B, C, D, A, E")
- ( = 4, = 1) When this happens, you should output the playlist.