Solve problem 41 using C++ and Python.