#P3666. COWBASIC Evaluation

    ID: 16917 Type: Default 1000ms 256MiB

COWBASIC Evaluation

COWBASIC Evaluation

Bessie invented COWBASIC, a simple programming language that supports two key features: addition and MOO loops. In COWBASIC, the command add increments a variable by 1, and all additions are performed modulo \(10^9+7\). The MOO x command begins a loop that repeats the block of code inside it exactly x times, and every loop is properly terminated with an END statement. Both additions and MOO loops can be nested arbitrarily. Given a valid COWBASIC program, compute and return the final result modulo \(10^9+7\>.

inputFormat

The input consists of multiple lines representing a valid COWBASIC program. Each line is one of the following:

  • add: Increments the accumulator by 1.
  • MOO x: Begins a loop that will execute the contained block of code exactly x times (with x being a positive integer).
  • END: Marks the end of a loop block.

It is guaranteed that the program is syntactically correct.

outputFormat

Output a single integer: the result of running the program, computed modulo \(10^9+7\).

sample

add
1