ACM Midatlantic programming contest 2014, Problem C Thoughts: Build a binary tree corresponding rather exactly to the way the scales look. Do this by parsing the input. Grammar: System = or or Number = {1..9} or followed by {0..9} // i.e. a seq of digits Variable = {A..Z} // i.e. a cap letter) Bar = [ ] Pseudocode: Insight: An array of assignments of values to variables can be maintained such that every variable is either Free, a constant, or a linear expression, ax + b, in another variable x, where a and b are constants. Then every System has a value that can also be expressed as ax+b where a and b are numbers and x is a variable. To do this may involve updating the array of variable assignments. Solution: Parse input and build tree. The tree can be traversed in depth first fashion computing the value of each bar at postfix node traversal time (3rd visit -- coming up from below right).