working solution to gcj 2011 QR B-small

this contains a working solution for the google code jam 2011
qualification round problem B.

contains the actual input and output that passed the contest.