Solve problem 142 using Python.