Code for problem 54.