Given nested Fygon loops with inclusive ranges over variables and n, compute the asymptotic complexity C*n^k of the single lag execution count, with C as an irreducible fraction.
Medium7MathCombinatoricsImplementationSimulationNo attempts yetTime limit3sMemory limit512 MBA new version of the programming language Fygon is out. Fygon 2.0 still has only two statements.
The first statement is lag. It replaces almost any other statement. The second statement is a for loop.
for <variable> in range(<from>, <to>):
<body>
<variable> from <from> to <to>, both inclusive.<from> is greater than <to>, <body> does not run at all.<variable> is a lowercase letter from a to z, except n, which is a variable defined before the given code fragment.<from> and <to> can be any variable defined in an outer loop. On top of that, <from> can be 1 and <to> can be n.<body> of the loop is indented by four spaces and contains at least one statement.If you know Fygon 1.0, note that Fygon 2.0 is not backwards compatible, because the range function now takes two parameters.
The new version runs much faster, so programs can nest for loops more deeply. For that reason the exact number of operations no longer matters, only the asymptotic complexity of the program. In every program given to you, all for loops are nested in a single chain, and exactly one lag statement sits inside all of them. All loop variables are distinct, and none of them is n.
Let f(n) be the number of lag operations the program executes, as a function of n. For a non-negative integer k and a positive rational number C, we call C⋅nk the asymptotic complexity of the program if
limn→∞C⋅nkf(n)=1
Given a Fygon 2.0 program, find its asymptotic complexity.
The first line contains one integer m, the number of lines of the Fygon 2.0 program. The next m lines contain the program itself.
The program has at least 1 and at most 20 for statements, and every for statement contains either one nested for statement or the lag statement, so 2≤m≤21.
Print k and C on one line, separated by a single space. Print C as an irreducible fraction p/q, where p and q are coprime positive integers. Print the denominator even when it equals 1, so write 1/1 and not 1.