My code and some solutions I read from Internet, for Google Code Jam question.