Solved prob35 in python