the exercise of Introduction to Algorithms