Solves Problem 36 in Python