public static void solve ( Scanner sc ) {
  int n = sc . nextInt ( ) ;
  HashMap < String , Node > map1 = new HashMap < > ( ) ;
  HashMap < String , Node > map2 = new HashMap < > ( ) ;
  Node start = new Node ( "start" ) ;
  Node end = new Node ( "end" ) ;
  for ( int i = 0 ;
  i < n ;
  i ++ ) {
    String firstWord = sc . next ( ) ;
    String secondWord = sc . next ( ) ;
    if ( ! map1 . containsKey ( firstWord ) ) {
      Node node = new Node ( firstWord ) ;
      map1 . put ( firstWord , node ) ;
      PushRelabelNodeEdge . addDirectedEdge ( start , node , 1 ) ;
    }
    if ( ! map2 . containsKey ( secondWord ) ) {
      Node node = new Node ( secondWord ) ;
      map2 . put ( secondWord , node ) ;
      PushRelabelNodeEdge . addDirectedEdge ( node , end , 1 ) ;
    }
    PushRelabelNodeEdge . addDirectedEdge ( map1 . get ( firstWord ) , map2 . get ( secondWord ) , 1 ) ;
  }
  ArrayList < Node > nodes = new ArrayList < > ( ) ;
  nodes . add ( start ) ;
  nodes . add ( end ) ;
  nodes . addAll ( map1 . values ( ) ) ;
  nodes . addAll ( map2 . values ( ) ) ;
  int flow = PushRelabelNodeEdge . getMaxFlow ( nodes , start , end ) ;
  int greedy = nodes . size ( ) - 2 - 2 * flow ;
  System . out . println ( n - flow - greedy ) ;
}

public static void solve ( Scanner sc ) { int n = sc . nextInt ( ) ; HashMap < String , Node > map1 = new HashMap < > ( ) ; HashMap < String , Node > map2 = new HashMap < > ( ) ; Node start = new Node ( " start " ) ; Node end = new Node ( " end " ) ; for ( int i = 0 ; i < n ; i ++ ) { String firstWord = sc . next ( ) ; String secondWord = sc . next ( ) ; if ( ! map1 . containsKey ( firstWord ) ) { Node node = new Node ( firstWord ) ; map1 . put ( firstWord , node ) ; PushRelabelNodeEdge . addDirectedEdge ( start , node , 1 ) ; } if ( ! map2 . containsKey ( secondWord ) ) { Node node = new Node ( secondWord ) ; map2 . put ( secondWord , node ) ; PushRelabelNodeEdge . addDirectedEdge ( node , end , 1 ) ; } PushRelabelNodeEdge . addDirectedEdge ( map1 . get ( firstWord ) , map2 . get ( secondWord ) , 1 ) ; } ArrayList < Node > nodes = new ArrayList < > ( ) ; nodes . add ( start ) ; nodes . add ( end ) ; nodes . addAll ( map1 . values ( ) ) ; nodes . addAll ( map2 . values ( ) ) ; int flow = PushRelabelNodeEdge . getMaxFlow ( nodes , start , end ) ; int greedy = nodes . size ( ) - 2 - 2 * flow ; System . out . println ( n - flow - greedy ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (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: (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)))) (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)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (string_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 (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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier) (decimal_integer_literal)))))) (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) consequence: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier) (decimal_integer_literal)))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) (decimal_integer_literal)))))) (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)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (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))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)) right: (binary_expression left: (decimal_integer_literal) right: (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)))))))