Time limit
2s
Memory limit
128 MB
You are given a program written in the fictional programming language L. Its lines are numbered from 1 through N, and execution starts at line 1. Whenever a command is executed, the number of that line is printed first. This also applies to commands such as ifgo that read input; the line number is printed before the input is read.
There are five commands.
ifgo x: read one input bit. If the bit is 1, continue at line x; if it is 0, continue at the next line.jump x: continue at line x.pass: do nothing and continue at the next line.die: terminate the program. This command never appears inside a loop.loop l c: treat the segment from line l through the current line as one loop, and make that segment execute c times in total. The execution that first reaches the current line is included, so after this command is executed, lines l through the current line are executed c-1 more times. After the repetitions finish, execution continues at the next line.The commands ifgo and jump may move only inside the loop that contains them. They cannot jump out of a loop, and they cannot jump from outside a nested loop into that nested loop. If loops are nested, the inner loop is completely contained in the outer loop.
If the last line is executed and its command is not die, execution restarts from line 1. A line may contain several spaces or tabs, and its total length including spaces and tabs is at most 80 characters.
Assume that the input bits read by ifgo are chosen to maximize the number of printed line numbers. Compute that maximum number.
The first line contains the number of lines N (1 ≤ N ≤ 100,000). The next N lines contain the L program, from line 1 through line N, in order.
Print the maximum number of times a line number can be printed. If this maximum is greater than 1,000,000,000, print infinity.