solved problem 14 in python and c++