Solve function implemented