public static void main ( String [ ] args ) {
  Scanner in = new Scanner ( System . in ) ;
  int N = in . nextInt ( ) ;
  int S = in . nextInt ( ) ;
  int [ ] buy = new int [ 100001 ] ;
  int [ ] sell = new int [ 100001 ] ;
  for ( int n = 0 ;
  n < N ;
  n ++ ) {
    String type = in . next ( ) ;
    int p = in . nextInt ( ) ;
    int q = in . nextInt ( ) ;
    int [ ] A = ( type . charAt ( 0 ) == 'B' ) ? buy : sell ;
    A [ p ] += q ;
  }
  int sellS = S ;
  int p = 0 ;
  while ( sellS > 0 && p < sell . length ) {
    if ( sell [ p ] > 0 ) {
      sellS -- ;
    }
    p ++ ;
  }
  p -- ;
  while ( p >= 0 ) {
    if ( sell [ p ] > 0 ) {
      System . out . println ( "S " + p + " " + sell [ p ] ) ;
    }
    p -- ;
  }
  int buyS = S ;
  for ( p = buy . length - 1 ;
  p >= 0 ;
  p -- ) {
    if ( buy [ p ] > 0 && buyS > 0 ) {
      buyS -- ;
      System . out . println ( "B " + p + " " + buy [ p ] ) ;
    }
  }
}

public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int N = in . nextInt ( ) ; int S = in . nextInt ( ) ; int [ ] buy = new int [ 100001 ] ; int [ ] sell = new int [ 100001 ] ; for ( int n = 0 ; n < N ; n ++ ) { String type = in . next ( ) ; int p = in . nextInt ( ) ; int q = in . nextInt ( ) ; int [ ] A = ( type . charAt ( 0 ) == ' B ' ) ? buy : sell ; A [ p ] += q ; } int sellS = S ; int p = 0 ; while ( sellS > 0 && p < sell . length ) { if ( sell [ p ] > 0 ) { sellS -- ; } p ++ ; } p -- ; while ( p >= 0 ) { if ( sell [ p ] > 0 ) { System . out . println ( " S ▁ " + p + " ▁ " + sell [ p ] ) ; } p -- ; } int buyS = S ; for ( p = buy . length - 1 ; p >= 0 ; p -- ) { if ( buy [ p ] > 0 && buyS > 0 ) { buyS -- ; System . out . println ( " B ▁ " + p + " ▁ " + buy [ p ] ) ; } } }
(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: (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))))) (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: (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: (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: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal))) consequence: (identifier) alternative: (identifier)))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (field_access object: (identifier) field: (identifier))))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (update_expression (identifier))))) (expression_statement (update_expression (identifier))))) (expression_statement (update_expression (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (array_access array: (identifier) index: (identifier)))))))) (expression_statement (update_expression (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) (for_statement init: (assignment_expression left: (identifier) right: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (block (expression_statement (update_expression (identifier))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (binary_expression left: (binary_expression left: (string_literal) right: (identifier)) right: (string_literal)) right: (array_access array: (identifier) index: (identifier))))))))))))