Solution to SPOJ's bitmap problem.