Peter got tired of using C++ in his computer engineering class, so he decided to create a new language called Sleep++. Sleep++ programs can only do one thing: sleep.
Each line in a Sleep++ program can be one of three commands: sleep
, repeat42
, and endrepeat
.
The sleep
command makes the computer sleep for second.
repeat42
and endrepeat
form a loop where the code in between them gets executed times. These loops may be nested.
After coming up with this amazing language, Peter wrote an interpreter for it in C++ (of course), but now he faces a big problem: many of his Sleep++ programs seem to sleep forever. Can you help Peter determine how much time a Sleep++ program spends sleeping?
Input Specification
The first line will contain an integer , the number of lines in the Sleep++ program.
The next lines will each be one of the three commands: sleep
, repeat42
, and endrepeat
.
The Sleep++ program is not guaranteed to be valid (repeat42
and endrepeat
might not be balanced).
Output Specification
If the Sleep++ program is valid, output the number of seconds the program will spend sleeping, modulo .
Otherwise, output SyntaxError
.
Sample Input 1
7
repeat42
sleep
repeat42
sleep
sleep
endrepeat
endrepeat
Sample Output 1
3570
Explanation for Sample 1
This is a nested loop. seconds of sleep.
Sample Input 2
6
repeat42
repeat42
endrepeat
endrepeat
repeat42
endrepeat
Sample Output 2
0
Sample Input 3
4
repeat42
repeat42
sleep
endrepeat
Sample Output 3
SyntaxError
Comments