Code for problem 353D.