#9 Solver for problem 27