public static boolean solve ( String n , int l ) {
  if ( l < 3 ) {
    if ( Integer . parseInt ( n ) % 8 == 0 ) return true ;
    n = new String ( ( new StringBuilder ( ) ) . append ( n ) . reverse ( ) ) ;
    if ( Integer . parseInt ( n ) % 8 == 0 ) return true ;
    return false ;
  }
  int [ ] hash = new int [ 10 ] ;
  for ( int i = 0 ;
  i < l ;
  i ++ ) hash [ n . charAt ( i ) - '0' ] ++ ;
  for ( int i = 104 ;
  i < 1000 ;
  i += 8 ) {
    int dup = i ;
    int [ ] freq = new int [ 10 ] ;
    freq [ dup % 10 ] ++ ;
    dup = dup / 10 ;
    freq [ dup % 10 ] ++ ;
    dup = dup / 10 ;
    freq [ dup % 10 ] ++ ;
    dup = i ;
    if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ;
    dup = dup / 10 ;
    if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ;
    dup = dup / 10 ;
    if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ;
    return true ;
  }
  return false ;
}

public static boolean solve ( String n , int l ) { if ( l < 3 ) { if ( Integer . parseInt ( n ) % 8 == 0 ) return true ; n = new String ( ( new StringBuilder ( ) ) . append ( n ) . reverse ( ) ) ; if ( Integer . parseInt ( n ) % 8 == 0 ) return true ; return false ; } int [ ] hash = new int [ 10 ] ; for ( int i = 0 ; i < l ; i ++ ) hash [ n . charAt ( i ) - '0' ] ++ ; for ( int i = 104 ; i < 1000 ; i += 8 ) { int dup = i ; int [ ] freq = new int [ 10 ] ; freq [ dup % 10 ] ++ ; dup = dup / 10 ; freq [ dup % 10 ] ++ ; dup = dup / 10 ; freq [ dup % 10 ] ++ ; dup = i ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; dup = dup / 10 ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; dup = dup / 10 ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; return true ; } return false ; }
(method_declaration (modifiers) type: (boolean_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (return_statement (true))) (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (method_invocation object: (parenthesized_expression (object_creation_expression type: (type_identifier) arguments: (argument_list))) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (return_statement (true))) (return_statement (false)))) (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 (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: (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_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: (decimal_integer_literal)) update: (assignment_expression left: (identifier) right: (decimal_integer_literal)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (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 (decimal_integer_literal))))) (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (expression_statement (update_expression (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) consequence: (continue_statement)) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) consequence: (continue_statement)) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))) right: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))) consequence: (continue_statement)) (return_statement (true)))) (return_statement (false))))