This Python code will solve the Good Luck challenge in CodeJam 2013's Round 1A C.