public static void main ( String [ ] args ) {
  Scanner in = new Scanner ( System . in ) ;
  String str ;
  HashSet < String > set = new HashSet < String > ( ) ;
  int ans = 0 ;
  while ( in . hasNextLine ( ) ) {
    str = in . nextLine ( ) ;
    if ( str . isEmpty ( ) ) break ;
    if ( str . charAt ( 0 ) == '+' || str . charAt ( 0 ) == '-' ) {
      String res = "" ;
      int m_id = 0 ;
      for ( int i = 1 ;
      i < str . length ( ) ;
      i ++ ) {
        if ( str . charAt ( i ) == ':' ) {
          m_id = i ;
          break ;
        }
        res += str . charAt ( i ) ;
      }
      if ( str . charAt ( 0 ) == '+' ) set . add ( res ) ;
      if ( str . charAt ( 0 ) == '-' ) set . remove ( res ) ;
    }
    else {
      String res = "" ;
      int m_id = 0 ;
      for ( int i = 1 ;
      i < str . length ( ) ;
      i ++ ) {
        if ( str . charAt ( i ) == ':' ) {
          m_id = i ;
          break ;
        }
      }
      ans += ( str . length ( ) - m_id - 1 ) * set . size ( ) ;
    }
  }
  System . out . println ( ans ) ;
}

public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String str ; HashSet < String > set = new HashSet < String > ( ) ; int ans = 0 ; while ( in . hasNextLine ( ) ) { str = in . nextLine ( ) ; if ( str . isEmpty ( ) ) break ; if ( str . charAt ( 0 ) == ' + ' || str . charAt ( 0 ) == ' - ' ) { String res = " " ; int m_id = 0 ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ' : ' ) { m_id = i ; break ; } res += str . charAt ( i ) ; } if ( str . charAt ( 0 ) == ' + ' ) set . add ( res ) ; if ( str . charAt ( 0 ) == ' - ' ) set . remove ( res ) ; } else { String res = " " ; int m_id = 0 ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ' : ' ) { m_id = i ; break ; } } ans += ( str . length ( ) - m_id - 1 ) * set . size ( ) ; } } System . out . println ( ans ) ; }
(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))) (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (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: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal)))) consequence: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_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 (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (break_statement))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))) right: (character_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) alternative: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (string_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 (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) right: (character_literal))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (break_statement))))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier)) right: (decimal_integer_literal))) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))