GCJ 2012 round1C problemC another solution (but more slow..)