URI Online Judge | 1945


By Emilio Wuerges, UFFS BR Brazil

Timelimit: 1

Centuries after the alien invasion, after mankind had been rebuild completely, a very old set of programs was discovered in an obsolete programming language, called Java++. For historical curiosity, you were assigned to understand the meaning of these programs.

Your task is to write a simulator for these programs, and as initial test, this simulator must be able to calculate the value of the last assigned variable of each program.


Each input consists of 1 program. The program only contains 2 kinds of instructions. One instruction to assign a variable and one to perform a sum.

Assignment instructions have the format:

A := B

Where A is a variable name and B is a positive integer.

Sum instructions have the format:

A := B + C

Where A is a variable name and B or C are either a variable name or a positive integer.

Tokens of these programs are always separated by spaces and instructions are separated by a line break.

Only combinations of at most 8 lower case letters are considered as valid variable names.

Programs have, at most, 2000 instructions

Variables are assigned, at most, only once.


Output consists of only 1 line, with only one positive integer number, containing the last value of the last variable assigned, be it by a direct assignment or by a sum.

Input Sample Output Sample

a := 2
b := 1
c := a + b
d := a + b


Input Sample Output Sample

a := 0
b := 1
c := a + b
d := a + b
e := a + c
f := 7