Please help me, I'm tired getting wrong answer, my approach is not wrong!

Continuing the discussion from PGRID1 - Editorial:

First things first: stop printing out the extra blank line, and see if that helps (I can’t remember how strict the Online Judge is about this).


You using int?
Try Long


Thanks for the help! It wasn’t because of the extra line…It was because I was using int instead of long!
I still though have a doubt , why was it a wrong answer because of this… perhaps i should get a runtime error… Am i wrong??

No, Integer overflow doesn’t result in a runtime error in Java. When you add some value to the integer variable and if the result is out of range of Integer, it simply assumes 2’s complement and the value becomes Negative.
Hence WA.


Ohh, Got it. Thank you