Problem E
Game of Throwns
Daenerys frequently invents games to help teach her second grade Computer Science class about various aspects of the discipline. For this week’s lesson she has the children form a circle and (carefully) throw around a petrified dragon egg.
The
-
a number
, indicating that the egg is to be thrown to the child who is positions clockwise from the current egg holder, wrapping around if necessary. If is negative, then the throw is to the counter-clockwise direction. -
the phrase undo
, indicating that the last throws should be undone. Note that undo commands never undo other undo commands; they just undo commands described in item above.
For example, if there are
Daenerys would like a little program that determines where the egg should end up if her commands are executed correctly. Don’t ask what happens to the children if this isn’t the case.
Input
Input consists of two lines. The first line contains two
positive integers
Output
Display the number of the child with the egg at the end of the game.
Sample Input 1 | Sample Output 1 |
---|---|
5 4 8 -2 3 undo 2 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
5 10 7 -3 undo 1 4 3 -9 5 undo 2 undo 1 6 |
2 |