The Department of Computer Science and Engineering runs courses dealing not only with algorithms but also with computer hardware. One such introductory course explains basic principles of integrated circuits (“chips”), binary logic, boolean algebra, etc. As you may know, the very basic units of logical circuits are called gates. A gate is an element performing one simple logical operation. It can be connected to other gates using lines.
Logical circuits may be drawn as pictures with the gates represented as squares with inputs on the left and outputs on the right. In each square, there is a symbol that determines the gate type: Number 1 denotes an OR gate (its outputs are 0 if and only if there is no input with the value of 1), & is an AND gate (outputs are 1 if and only if there is no 0 input), and = is a XOR gate (outputs are 1 if and only if there is an odd number inputs that have the value of 1).
Your task is to scan such a “picture” and compute values of all named circuit outputs. The lines may split and join again but you may assume that each “value consumer” (input port of a gate or a named output) will be connected to exactly one “value source” (output port of a gate or an input value). There will be no feedback loops, i.e., there exists no cycle that would lead through the same gate twice.