Problems
Электронная таблица
Электронная таблица
You are to write a program emulating a very simple spreadsheet application. It works with a table with \textbf{9} rows, from "\textbf{1}" to "\textbf{9}", and \textbf{26} columns, from "\textbf{A}" to "\textbf{Z}". Table \textit{cells} are referenced by names composed of column and row codes, ex. "\textbf{B1}", "\textbf{S8}".
Each cell contains an \textit{expression} up to \textbf{255} characters long. Expressions use integer constants, cell references, parenthesis, operators "\textbf{+}", "\textbf{--}", "\textbf{*}", and "\textbf{/}" (whole division). For example: \textbf{567}, \textbf{E8/2}, \textbf{(3+B3)*(C4--1)} are all valid expressions. All operators are whole, all arguments and results are guaranteed to be less than \textbf{1000000}. Division by zero yields zero.
If the value of the cell referenced by some expression is not defined, it is presumed to be 0 (zero). The situation when two or more cells are mutually dependent on each other is considered a special case of "\textit{circular reference}".
\InputFile
First input line contains number of expressions N. Following N lines are in format =. All expressions are correct, and each cell is defined by at most one expression.
\OutputFile
Output file must contain single line with either the value of the cell "\textbf{A1}" or number \textbf{1000000} (one million) if the value of \textbf{A1} cannot be computed due to a circular reference.
Input example #1
4 A1=B1+C5 B1=20 C5 =B1 /D7-E1*E1 E1=(3+1)*2
Output example #1
-44