Run Time Error (NZEC) Problem

The program below runs smooth on IDE but when I submit it to Codechef it returns “Runtime Error(NZEC)” message. The function of this program is to take in strings consisting of 0’s and 1’s as input and to determine if all the 1’s in the string occur together or not and return “YES” or "NO’ accordingly.(For example(01111100-YES; 011001-NO)). The link to the Codechef question is here :Bear and Segment 01
The code is as given below:

  import java.util.Scanner;
  class Check 
  {
  public static void main(String args[])
  {
  Scanner p=new Scanner(System.in);
  int a=p.nextInt();
  for(int i=1;i<=a;i++)    //This loop takes in the desired number of test cases
  {
  long b=p.nextInt();
  if(b==0)                 //If string consists of only zeroes, this statement returns NO
  {
  System.out.println("NO");
  }
  for(int j=1;b>0;j++)     //This loop determine's the first occurrence of 1 in the string
  {
  long c=b%10;
  if(c==0)
  {
   b=b/10;
  }
  if(c==1)
  {
  break;
  }
  }
  for(int k=1;b>0;k++) //This loop determines the last occurrence of 1 and whether 0 occurs between them
  {
  long d=b%10;
               
  if(d==0)
  {
  System.out.println("NO");
  break;
  }
  b=(b-d)/10;
  if(d==1&&b!=0)
  {
  continue;
  }
  if(d==1&&b==0)
  {
  System.out.println("YES");
  }
               
  }
  }
      
  }
  }
I cannot determine the cause of run time error given by Codechef code tester. Please help me out.

You are taking the input as long! But dear, the string can cross 50 digits, and hence the maximum capacity of long.

Long can hold till ~10^18. But string can be upto 50 digits, meaning roughly 1.1111111111 x 10^50. You need to store it in a string and iterate through it. Else your code will give a Mismatch input exception or something when it encounters a string of length >18.

//