problem 51(solved by python)