Solve SPOJ problem #1112, NSTEPS