Solved problem13 in python3