public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  String s = sc . next ( ) ;
  int x = 0 ;
  int y = 0 ;
  int uk = 0 ;
  for ( int i = 0 ;
  i < s . length ( ) ;
  i ++ ) {
    switch ( s . substring ( i , i + 1 ) ) {
      case "R" : x ++ ;
      break ;
      case "L" : x -- ;
      break ;
      case "D" : y -- ;
      break ;
      case "U" : y ++ ;
      break ;
      case "?" : uk ++ ;
      break ;
    }
  }
  int ans = Math . abs ( x ) + Math . abs ( y ) ;
  int t = sc . nextInt ( ) ;
  if ( t == 1 ) System . out . println ( ans + uk ) ;
  else {
    if ( ans >= uk ) System . out . println ( ans - uk ) ;
    else System . out . println ( ( uk - ans ) % 2 ) ;
  }
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; String s = sc . next ( ) ; int x = 0 ; int y = 0 ; int uk = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s . substring ( i , i + 1 ) ) { case " R " : x ++ ; break ; case " L " : x -- ; break ; case " D " : y -- ; break ; case " U " : y ++ ; break ; case " ? " : uk ++ ; break ; } } int ans = Math . abs ( x ) + Math . abs ( y ) ; int t = sc . nextInt ( ) ; if ( t == 1 ) System . out . println ( ans + uk ) ; else { if ( ans >= uk ) System . out . println ( ans - uk ) ; else System . out . println ( ( uk - ans ) % 2 ) ; } }
(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: (integral_type) declarator: (variable_declarator name: (identifier) value: (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: (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 (switch_expression condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal))))) body: (switch_block (switch_block_statement_group (switch_label (string_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (string_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (string_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (string_literal)) (expression_statement (update_expression (identifier))) (break_statement)) (switch_block_statement_group (switch_label (string_literal)) (expression_statement (update_expression (identifier))) (break_statement)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier))))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (identifier) right: (identifier))))) alternative: (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal))))))))))