#P7053. [NWRRC 2015] Fygon

[NWRRC 2015] Fygon

题目描述

Frederick is a young programmer. He participates in all programming contests he can find and always uses his favorite programming language Fygon. Unfortunately, he often receives Time Limit Exceeded outcome, even when his algorithm is asymptotically optimal. That's because the Fygon interpreter is very slow. Nevertheless, Frederick likes Fygon so much, that he uses non-asymptotical optimizations to fit the solution into time limit. To make it easier, he asks you to write a program, which will be able to estimate the exact number of operations that his Fygon program makes.

For simplicity, we will assume that Fygon has only two statements. The first statement is lag. It substitutes almost any other statement. The second statement is a for loop:

for in range ():():

This means that iterates over values from 00 to 1−1 . In Fygon is a lowercase letter from a to zz , and is either already defined or a positive integer constant. The of the loop is indented by four spaces and contains at least one statement.

The program receives the input in the variable nn . This variable has special meaning and cannot be used as a loop variable.

Your task is to find the formula that calculates the number of performed lag operations by the given Fygon program, depending on the value of the variable nn .

输入格式

The input file contains the Fygon program. No two loops use the same variable as iterators. Each variable used inside a range is either nn or declared in some outer loop.

The program has at most 2020 statements and at most 66 of them are loops. All integer constants are from 11 to 99 . Outpu

输出格式

Output the formula for the number of performed lag operations depending on nn . The length of the formula should be at most 100100 characters (excluding spaces). The formula should correspond to the following grammar:

$〈Expressio_n〉 ::= 〈Product〉 ( (‘+' | ‘-') 〈Product〉) ^{ \times }$

$〈Product〉 ::= 〈Value〉 (‘ \times '〈Value〉) ^{ \times }$

$〈Value〉 ::= ‘n' | 〈Number〉 | ‘-'〈Value〉 | ‘('〈Expressio_n〉‘)'$

$〈Number〉 ::= [‘0' \cdots ‘9'] ^{+} (‘/' [‘0' \cdots ‘9'] ^{+}) ^{?}$

for i in range(n):
    for j in range(i):
        lag
for x in range(5):
    for y in range(n):
        for z in range(n):
            lag
    lag

1/2 * n * (n-1) + 5 * (n*n + 1)

提示

Time limit: 2 s, Memory limit: 256 MB.