Problem 14. Runs in 40s! Too slow :(