Problem 10. Solved but slow.