Added the solution code for the numerical stability problem.