private static void sport ( String [ ] a ) {
  int [ ] [ ] dp = new int [ 26 ] [ 26 ] ;
  boolean [ ] [ ] can = new boolean [ 26 ] [ 26 ] ;
  int ans = 0 ;
  for ( String s : a ) {
    int l = s . charAt ( 0 ) - 'a' ;
    int r = s . charAt ( s . length ( ) - 1 ) - 'a' ;
    for ( int i = 0 ;
    i < 26 ;
    i ++ ) {
      if ( can [ i ] [ l ] ) {
        can [ i ] [ r ] = true ;
        dp [ i ] [ r ] = Math . max ( dp [ i ] [ r ] , dp [ i ] [ l ] + s . length ( ) ) ;
      }
    }
    can [ l ] [ r ] = true ;
    dp [ l ] [ r ] = Math . max ( dp [ l ] [ r ] , s . length ( ) ) ;
  }
  for ( int i = 0 ;
  i < 26 ;
  i ++ ) {
    ans = Math . max ( ans , dp [ i ] [ i ] ) ;
  }
  System . out . println ( ans ) ;
}

private static void sport ( String [ ] a ) { int [ ] [ ] dp = new int [ 26 ] [ 26 ] ; boolean [ ] [ ] can = new boolean [ 26 ] [ 26 ] ; int ans = 0 ; for ( String s : a ) { int l = s . charAt ( 0 ) - ' a ' ; int r = s . charAt ( s . length ( ) - 1 ) - ' a ' ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( can [ i ] [ l ] ) { can [ i ] [ r ] = true ; dp [ i ] [ r ] = Math . max ( dp [ i ] [ r ] , dp [ i ] [ l ] + s . length ( ) ) ; } } can [ l ] [ r ] = true ; dp [ l ] [ r ] = Math . max ( dp [ l ] [ r ] , s . length ( ) ) ; } for ( int i = 0 ; i < 26 ; i ++ ) { ans = Math . max ( ans , dp [ i ] [ i ] ) ; } System . out . println ( ans ) ; }
(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: (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)) dimensions: (dimensions_expr (decimal_integer_literal))))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (decimal_integer_literal)) dimensions: (dimensions_expr (decimal_integer_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (enhanced_for_statement type: (type_identifier) name: (identifier) value: (identifier) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) 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: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) (binary_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))))))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) (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: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (array_access array: (array_access array: (identifier) index: (identifier)) index: (identifier)))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))