Code for problem 399A.