DWITE Online Computer Programming Contest
January 2008
Problem 5
It all adds up

Business world runs on spreadsheets, and Tony needs one small enough to run on a toaster -- meaning it will have just 5 by 5 cells, and only basic operations: +, -, *

The input file DATA5.txt will contain 25 lines -- first 5 lines are column A: A1, A2, A3, A4, A5. Second 5 lines are column B: B1, B2, B3, B4, B5. Etc. Each line will hold either an integer, or an expression in the form =CELL (operator CELL)*, where (operator CELL) part could be repeated up to 5 times. All input values will be integers, 0 <= n <= 99999. No expression will exceed the value of 99999. There will be no infinite loops in equations. Refer to the sample input for examples.

The output file OUT5.txt will contain 25 lines -- a solved spreadsheet, where each line holds an integer value. The calculations are primitive, the order of calculations are from left to right. That is, an expression =2 + 2 * 3 will equate to 12, not 8.

Sample Input:
0
1
=A2
=A2 + A3
=A4 + A3
=A2 * A4 + A5
8
=B1 * A4 + 3
=B1 * 4 + 1
=5 + 5 + 5 * 2 + 4
55
89
144
233
377
=D3 - D2
=D4 - D3
=D5 - D4
2584
4181
6765
10946
17711
28657
46368
		        
Sample Output:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368