Solves Problem 44 in Python