Lottery problem on Topcoder