P5756 [NOI2000] Program Analyzer
Description
The Backus–Naur Form (BNF) of the Tiny Basm language (abbreviated as TB) is:

Examples of incorrect statements (no incorrect statements will appear in the input file):
- `10 A+1.5` (does not match the definition of an addition statement, because the added value is not an integer)
- `20 A ?` (does not match the definition of an output statement, because there is an extra space)
- `30 IF A=B GO 10` (does not match the definition of a conditional statement; it should not be variable $=$ variable)
$\\$
Execution of a TB program:
- The program starts executing from the statement with the smallest line number. Before encountering any conditional statement, it executes statements in increasing order of line number.
- All variables are automatically initialized to $0$ before execution.
- An addition statement adds the integer in the statement to the value of the variable, and stores the result back into that variable.
- An output statement displays the value of the variable in the statement on the monitor.
- When executing a conditional statement, the following jump statement is executed if and only if the variable in the statement is equal to the integer value immediately after the equals sign. All integer values in this statement are at most $4$ digits.
- After a jump statement is executed, the program jumps to the statement with the line number specified after $\tt GO$.
- When the program executes an end statement, the entire program terminates.
- Assume the system can handle integers of any size without overflow.
Please write a program that, for a given TB program $P$, computes the number of statements executed by the program (for a conditional statement, regardless of whether the jump succeeds, it is counted as executing exactly one statement).
Input Format
- The input is a TB program $P$, with no more than $100$ statements (lines).
- The length of each statement in $P$ does not exceed $20$ characters.
- For every jump statement in $P$, the line number after $\tt GO$ definitely has a corresponding statement.
- $P$ may contain multiple end statements with different line numbers.
- The statement with the largest line number in $P$ is definitely an end statement.
- All line numbers in $P$ are no greater than $3000$.
- The input file does not necessarily list $P$ in increasing order of line numbers.
Output Format
- There is exactly one line:
If the program can terminate normally, output the number of statements executed;
if the program cannot terminate normally, output $-1$.
Explanation/Hint
**Sample Explanation**
The executed line numbers in order are $10→20→30→40→50→20→30→40→50→20→60$.
A total of $11$ statements are executed.
Translated by ChatGPT 5