Problem 39

Python 2.7