Submit solution

Points: 7
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

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 1 second.

repeat42 and endrepeat form a loop where the code in between them gets executed 42 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 N (1 \le N \le 10^4), the number of lines in the Sleep++ program.

The next N 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 10^9+7.

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. (1+2\times42)\times42=3570 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

There are no comments at the moment.