public static void solve ( String sr ) {
  if ( sr . length ( ) % 2 != 0 ) {
    System . out . println ( "-1" ) ;
    return ;
  }
  int [ ] arr = new int [ 4 ] ;
  for ( int i = 0 ;
  i < sr . length ( ) ;
  i ++ ) {
    if ( sr . charAt ( i ) == 'L' ) arr [ 0 ] ++ ;
    else if ( sr . charAt ( i ) == 'R' ) arr [ 1 ] ++ ;
    else if ( sr . charAt ( i ) == 'U' ) arr [ 2 ] ++ ;
    else if ( sr . charAt ( i ) == 'D' ) arr [ 3 ] ++ ;
  }
  int count = 0 ;
  int diff1 = Math . abs ( arr [ 0 ] - arr [ 1 ] ) ;
  int diff2 = Math . abs ( arr [ 2 ] - arr [ 3 ] ) ;
  count = Math . min ( diff1 , diff2 ) + Math . abs ( diff1 - diff2 ) / 2 ;
  System . out . println ( count ) ;
}

public static void solve ( String sr ) { if ( sr . length ( ) % 2 != 0 ) { System . out . println ( " - 1" ) ; return ; } int [ ] arr = new int [ 4 ] ; for ( int i = 0 ; i < sr . length ( ) ; i ++ ) { if ( sr . charAt ( i ) == ' L ' ) arr [ 0 ] ++ ; else if ( sr . charAt ( i ) == ' R ' ) arr [ 1 ] ++ ; else if ( sr . charAt ( i ) == ' U ' ) arr [ 2 ] ++ ; else if ( sr . charAt ( i ) == ' D ' ) arr [ 3 ] ++ ; } int count = 0 ; int diff1 = Math . abs ( arr [ 0 ] - arr [ 1 ] ) ; int diff2 = Math . abs ( arr [ 2 ] - arr [ 3 ] ) ; count = Math . min ( diff1 , diff2 ) + Math . abs ( diff1 - diff2 ) / 2 ; System . out . println ( count ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))) (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: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) 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: (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal)))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (expression_statement (update_expression (array_access array: (identifier) index: (decimal_integer_literal)))))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (array_access array: (identifier) index: (decimal_integer_literal))))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (identifier))) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier)))) right: (decimal_integer_literal))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))