http://www.codechef.com/NOV13/problems/SPOTWO