Refined problem 05 solution.