memorize the solve function