Solved problem14 in python3