Problem 5: complete solution.