#3 Solver for problem 21