public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( new BufferedInputStream ( System . in ) ) ;
  String string ;
  int sum = 0 ;
  HashSet hs = new HashSet < String > ( ) ;
  while ( sc . hasNextLine ( ) ) {
    string = sc . nextLine ( ) ;
    if ( string . isEmpty ( ) ) break ;
    if ( string . charAt ( 0 ) == '+' ) {
      hs . add ( string . substring ( 1 , string . length ( ) ) ) ;
    }
    else if ( string . charAt ( 0 ) == '-' ) {
      hs . remove ( string . substring ( 1 , string . length ( ) ) ) ;
    }
    else {
      String [ ] str = string . split ( ":" ) ;
      if ( str . length != 1 ) sum += hs . size ( ) * str [ 1 ] . length ( ) ;
    }
  }
  System . out . println ( sum ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( new BufferedInputStream ( System . in ) ) ; String string ; int sum = 0 ; HashSet hs = new HashSet < String > ( ) ; while ( sc . hasNextLine ( ) ) { string = sc . nextLine ( ) ; if ( string . isEmpty ( ) ) break ; if ( string . charAt ( 0 ) == ' + ' ) { hs . add ( string . substring ( 1 , string . length ( ) ) ) ; } else if ( string . charAt ( 0 ) == ' - ' ) { hs . remove ( string . substring ( 1 , string . length ( ) ) ) ; } else { String [ ] str = string . split ( " : " ) ; if ( str . length != 1 ) sum += hs . size ( ) * str [ 1 ] . length ( ) ; } } System . out . println ( sum ) ; }
(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 (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))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (while_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) body: (block (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (if_statement condition: (parenthesized_expression (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) consequence: (break_statement)) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))) alternative: (block (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (string_literal))))) (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal))) consequence: (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (method_invocation object: (array_access array: (identifier) index: (decimal_integer_literal)) name: (identifier) arguments: (argument_list))))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))