solution to Angry Children problem