public static void process ( ) throws IOException {
  int n = sc . nextInt ( ) ;
  int x = sc . nextInt ( ) ;
  String str = sc . next ( ) ;
  int [ ] arr = new int [ n ] ;
  arr [ 0 ] = str . charAt ( 0 ) == '0' ? 1 : - 1 ;
  for ( int i = 1 ;
  i < n ;
  i ++ ) {
    if ( str . charAt ( i ) == '1' ) {
      arr [ i ] = arr [ i - 1 ] - 1 ;
    }
    else {
      arr [ i ] = arr [ i - 1 ] + 1 ;
    }
  }
  int last = arr [ n - 1 ] ;
  int count = 0 ;
  if ( x == 0 ) count ++ ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    if ( arr [ i ] == x && last == 0 ) {
      out . println ( - 1 ) ;
      return ;
    }
    if ( arr [ i ] == x ) {
      count ++ ;
      continue ;
    }
    if ( last == 0 ) {
      continue ;
    }
    int curr = arr [ i ] ;
    int val = x - curr ;
    if ( Math . abs ( val ) % Math . abs ( last ) == 0 ) {
      val /= last ;
      if ( val / Math . abs ( val ) == - 1 ) {
        continue ;
      }
      else {
        count ++ ;
      }
    }
  }
  println ( count ) ;
}

public static void process ( ) throws IOException { int n = sc . nextInt ( ) ; int x = sc . nextInt ( ) ; String str = sc . next ( ) ; int [ ] arr = new int [ n ] ; arr [ 0 ] = str . charAt ( 0 ) == '0' ? 1 : - 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '1' ) { arr [ i ] = arr [ i - 1 ] - 1 ; } else { arr [ i ] = arr [ i - 1 ] + 1 ; } } int last = arr [ n - 1 ] ; int count = 0 ; if ( x == 0 ) count ++ ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == x && last == 0 ) { out . println ( - 1 ) ; return ; } if ( arr [ i ] == x ) { count ++ ; continue ; } if ( last == 0 ) { continue ; } int curr = arr [ i ] ; int val = x - curr ; if ( Math . abs ( val ) % Math . abs ( last ) == 0 ) { val /= last ; if ( val / Math . abs ( val ) == - 1 ) { continue ; } else { count ++ ; } } } println ( count ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters) (throws (type_identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (ternary_expression condition: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)) consequence: (decimal_integer_literal) alternative: (unary_expression operand: (decimal_integer_literal))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal))))) alternative: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (decimal_integer_literal)))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (update_expression (identifier)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal))))) (return_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))) (continue_statement))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (continue_statement))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (decimal_integer_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) right: (unary_expression operand: (decimal_integer_literal)))) consequence: (block (continue_statement)) alternative: (block (expression_statement (update_expression (identifier))))))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier))))))