I also faced similar situation in java. My guess is that there maybe some non-integer character(s) present in the input or possible inputs are in different lines. I used BuffereredReader and then tokenizer to get the next tokens which is returning NZEC (link), but the exactly same solution applied using scanner.nextBigInteger() results into AC.