Google code jam solution