I solved the problem http://www.codechef.com/MAY14/problems/CHEFBM/ but when I print to console using System.out.println is causing NZEC runtime error.
If I comment out System.out.println statements then I am getting wrong answer as it's expected.
Total time for wrong answer is 0.06 but when I used the standard output the time is taking 0.66 and the program is failing with runtime error NZEC