public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int a = sc . nextInt ( ) ;
  int b = sc . nextInt ( ) ;
  int c = sc . nextInt ( ) ;
  int m = sc . nextInt ( ) ;
  PriorityQueue < Long > mUSB = new PriorityQueue < Long > ( ) ;
  PriorityQueue < Long > mPS = new PriorityQueue < Long > ( ) ;
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    long mouse = sc . nextInt ( ) ;
    String t = sc . next ( ) ;
    if ( t . contentEquals ( "USB" ) ) {
      mUSB . add ( mouse ) ;
    }
    else {
      mPS . add ( mouse ) ;
    }
  }
  long price = 0 ;
  int i = 0 ;
  for ( ;
  i < a && ! mUSB . isEmpty ( ) ;
  i ++ ) {
    price += mUSB . poll ( ) ;
  }
  int j = 0 ;
  for ( ;
  j < b && ! mPS . isEmpty ( ) ;
  j ++ ) {
    price += mPS . poll ( ) ;
  }
  int k = 0 ;
  for ( ;
  k < c ;
  k ++ ) {
    if ( ! mUSB . isEmpty ( ) && ! mPS . isEmpty ( ) ) {
      if ( mUSB . peek ( ) <= mPS . peek ( ) ) {
        price += mUSB . poll ( ) ;
      }
      else {
        price += mPS . poll ( ) ;
      }
    }
    else if ( ! mUSB . isEmpty ( ) ) {
      price += mUSB . poll ( ) ;
    }
    else if ( ! mPS . isEmpty ( ) ) {
      price += mPS . poll ( ) ;
    }
    else {
      break ;
    }
  }
  System . out . println ( ( i + j + k ) + " " + price ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a = sc . nextInt ( ) ; int b = sc . nextInt ( ) ; int c = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; PriorityQueue < Long > mUSB = new PriorityQueue < Long > ( ) ; PriorityQueue < Long > mPS = new PriorityQueue < Long > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { long mouse = sc . nextInt ( ) ; String t = sc . next ( ) ; if ( t . contentEquals ( " USB " ) ) { mUSB . add ( mouse ) ; } else { mPS . add ( mouse ) ; } } long price = 0 ; int i = 0 ; for ( ; i < a && ! mUSB . isEmpty ( ) ; i ++ ) { price += mUSB . poll ( ) ; } int j = 0 ; for ( ; j < b && ! mPS . isEmpty ( ) ; j ++ ) { price += mPS . poll ( ) ; } int k = 0 ; for ( ; k < c ; k ++ ) { if ( ! mUSB . isEmpty ( ) && ! mPS . isEmpty ( ) ) { if ( mUSB . peek ( ) <= mPS . peek ( ) ) { price += mUSB . poll ( ) ; } else { price += mPS . poll ( ) ; } } else if ( ! mUSB . isEmpty ( ) ) { price += mUSB . poll ( ) ; } else if ( ! mPS . isEmpty ( ) ) { price += mPS . poll ( ) ; } else { break ; } } System . out . println ( ( i + j + k ) + " ▁ " + price ) ; }
(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: (integral_type) 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: (integral_type) 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))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (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 (type_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: (identifier)) update: (update_expression (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: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal)))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) alternative: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (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 condition: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement condition: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (for_statement condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) right: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))) alternative: (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) alternative: (if_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) alternative: (block (break_statement))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) right: (string_literal)) right: (identifier)))))))