Solved problem12 in python3