Problem 2 of the CSUS programming competition