This problem is from a programming competition.