Codejam 2008 QA problem A (yet to debug)