#P7053. Fygon Operation Count

    ID: 20259 Type: Default 1000ms 256MiB

Fygon Operation Count

Fygon Operation Count

Frederick, a young programmer, uses his favorite language Fygon that contains only two statements: lag and for loops. In a Fygon program the lag statement counts as one operation. A for loop is written as for x in range(expr): where x is a lowercase letter (other than n) and expr is either a positive integer constant or a variable that has been defined earlier. The loop iterates with x taking values from 0 to expr − 1, and its body is indented by four spaces. Variables are local to their loops, and the input is given in the variable n (which cannot be used as a loop variable).

Your task is to compute the exact number of lag operations that the Fygon program will perform, as a function of the input n. Note that if a lag statement is inside nested loops, its contributions are multiplicative (or, more generally, summed over the appropriate ranges). For example, consider the program:

for i in range(n):
    for j in range(i):
        lag

This program executes lag a total of ( \sum_{i=0}^{n-1} i = \frac{n(n-1)}2) times.

inputFormat

The input consists of several lines. The first line contains an integer n. The remaining lines describe a Fygon program. Each for loop is written as for x in range(expr): and its body is indented by 4 spaces per nesting level.

outputFormat

Output a single integer which is the total number of lag operations performed by the Fygon program when the input variable n is set accordingly.

sample

10
lag
1