99HP: initial but ugly impl of problem 24