solved problem 5 in python and c++. 210576th person