Code for problem 81D.