Solving the balancing parentheses puzzle