Code for problem 358D.