Nasty Virus
Our programmers have been recently experiencing a strange phenomenon. Some old FORTRAN pro- grams that have been working for years suddenly stopped working!! A close inspection of the situation revealed the existence of a nasty virus in our computer. The virus wakes up every night, and adds random lines, some of them valid FORTRAN statements, to all FORTRAN programs. (The existing lines are not changed.) Furthermore, it was discovered that:
• the virus may insert lines ONLY BEFORE the last line and after the first line; • the virus may insert an assignment to a variable “v” in one of two ways:
- The original program does not contain any assignment to “v” — in this case the new assign- ment to “v” can be inserted anywhere in the original program. (before the last line)
- The original program does contain one or more assignments to “v” — in this case the new assignment to “v” can be inserted only after the last assignment to “v” in the original program. (before the last line)
You are to write a program that will read one corrupted FORTRAN program and restores the program to its original state.
Fortunately, the original FORTRAN programs compute values of certain functions by using ONLY assignment statements where the right-hand side expression of each assignment statement is an expres- sion over the operators: +, , /, - and operands {a, b, ... y, z, 0, 1, ... 9}.
Furthermore, our programs contained NO USELESS assignment statements (an assignment to a variable, v, is useless if the value of v is not consequently used in the program) and the last assignment statement of the program computed the value of the desired function.
Also, our smart programmers always start their program by a line of comment, ‘Cn’, where n is the number of lines (not counting the comment line itself) contained in the program.
Input
The input consists of one possible corrupted FORTRAN program containing only assignment statement as described above.
Output
The output, consists of the corrupted FORTRAN program in its original state.
Sample Input
C5
x=5+6
a=x+7
LLWWLLWLL
d=x+7
if (x-a)10,3,2
c=x+b
e=2x a=x*7
2/2 kljhkjh kjhkjhk kjh
y=xa+c+d
Sample Output
C5
x=5+6
a=x+7
d=x+7
c=x+b
y=xa+c+d