public static void main ( String [ ] args ) {
  Scanner scanner = new Scanner ( System . in ) ;
  String str = scanner . next ( ) ;
  char [ ] s = str . toCharArray ( ) ;
  int k = scanner . nextInt ( ) ;
  HashMap < Character , Integer > d = new HashMap < > ( ) ;
  for ( char elem : s ) {
    d . putIfAbsent ( elem , 0 ) ;
    d . replace ( elem , d . get ( elem ) + 1 ) ;
  }
  HashMap < Integer , ArrayList < Character >> dict = new HashMap < > ( ) ;
  for ( Map . Entry < Character , Integer > pair : d . entrySet ( ) ) {
    dict . putIfAbsent ( pair . getValue ( ) , new ArrayList < Character > ( ) ) ;
    ArrayList list = new ArrayList ( dict . get ( pair . getValue ( ) ) ) ;
    list . add ( pair . getKey ( ) ) ;
    dict . replace ( pair . getValue ( ) , list ) ;
  }
  ArrayList < Integer > list = new ArrayList < > ( dict . keySet ( ) ) ;
  int result = 0 ;
  for ( int elem : list ) {
    for ( char element : dict . get ( elem ) ) {
      if ( k >= elem ) {
        result ++ ;
        k -= elem ;
        str = str . replaceAll ( Character . toString ( element ) , "" ) ;
      }
    }
  }
  System . out . println ( d . size ( ) - result ) ;
  System . out . println ( str ) ;
}

public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; String str = scanner . next ( ) ; char [ ] s = str . toCharArray ( ) ; int k = scanner . nextInt ( ) ; HashMap < Character , Integer > d = new HashMap < > ( ) ; for ( char elem : s ) { d . putIfAbsent ( elem , 0 ) ; d . replace ( elem , d . get ( elem ) + 1 ) ; } HashMap < Integer , ArrayList < Character > > dict = new HashMap < > ( ) ; for ( Map . Entry < Character , Integer > pair : d . entrySet ( ) ) { dict . putIfAbsent ( pair . getValue ( ) , new ArrayList < Character > ( ) ) ; ArrayList list = new ArrayList ( dict . get ( pair . getValue ( ) ) ) ; list . add ( pair . getKey ( ) ) ; dict . replace ( pair . getValue ( ) , list ) ; } ArrayList < Integer > list = new ArrayList < > ( dict . keySet ( ) ) ; int result = 0 ; for ( int elem : list ) { for ( char element : dict . get ( elem ) ) { if ( k >= elem ) { result ++ ; k -= elem ; str = str . replaceAll ( Character . toString ( element ) , " " ) ; } } } System . out . println ( d . size ( ) - result ) ; System . out . println ( str ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (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: (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: (generic_type (type_identifier) (type_arguments (type_identifier) (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (decimal_integer_literal)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (decimal_integer_literal))))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier) (generic_type (type_identifier) (type_arguments (type_identifier))))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (enhanced_for_statement type: (generic_type (scoped_type_identifier (type_identifier) (type_identifier)) (type_arguments (type_identifier) (type_identifier))) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) (identifier)))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (integral_type) name: (identifier) value: (identifier) body: (block (enhanced_for_statement type: (integral_type) name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (update_expression (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (string_literal))))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))