public static void main ( String [ ] args ) throws Exception {
  List < String > commands = new ArrayList < > ( 0 ) ;
  while ( true ) {
    String s = reader . readLine ( ) ;
    if ( s != null && ! s . isEmpty ( ) ) {
      commands . add ( s ) ;
    }
    else {
      break ;
    }
  }
  int trafficCount = 0 ;
  int currentPeopleCount = 0 ;
  for ( int i = 0 ;
  i < commands . size ( ) ;
  ++ i ) {
    if ( commands . get ( i ) . startsWith ( "+" ) ) {
      ++ currentPeopleCount ;
    }
    else if ( commands . get ( i ) . startsWith ( "-" ) ) {
      -- currentPeopleCount ;
    }
    else {
      String [ ] parts = commands . get ( i ) . split ( ":" ) ;
      int msgLen = parts != null && parts . length > 1 ? parts [ 1 ] . length ( ) : 0 ;
      trafficCount += currentPeopleCount * msgLen ;
    }
  }
  System . out . println ( trafficCount ) ;
}

public static void main ( String [ ] args ) throws Exception { List < String > commands = new ArrayList < > ( 0 ) ; while ( true ) { String s = reader . readLine ( ) ; if ( s != null && ! s . isEmpty ( ) ) { commands . add ( s ) ; } else { break ; } } int trafficCount = 0 ; int currentPeopleCount = 0 ; for ( int i = 0 ; i < commands . size ( ) ; ++ i ) { if ( commands . get ( i ) . startsWith ( " + " ) ) { ++ currentPeopleCount ; } else if ( commands . get ( i ) . startsWith ( " - " ) ) { -- currentPeopleCount ; } else { String [ ] parts = commands . get ( i ) . split ( " : " ) ; int msgLen = parts != null && parts . length > 1 ? parts [ 1 ] . length ( ) : 0 ; trafficCount += currentPeopleCount * msgLen ; } } System . out . println ( trafficCount ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (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)) arguments: (argument_list (decimal_integer_literal))))) (while_statement condition: (parenthesized_expression (true)) body: (block (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 (binary_expression left: (binary_expression left: (identifier) right: (null_literal)) right: (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) alternative: (block (break_statement))))) (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 (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (string_literal)))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (if_statement condition: (parenthesized_expression (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (string_literal)))) consequence: (block (expression_statement (update_expression (identifier)))) alternative: (block (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))) name: (identifier) arguments: (argument_list (string_literal))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (binary_expression left: (binary_expression left: (identifier) right: (null_literal)) right: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (decimal_integer_literal))) consequence: (method_invocation object: (array_access array: (identifier) index: (decimal_integer_literal)) name: (identifier) arguments: (argument_list)) alternative: (decimal_integer_literal)))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier))))))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (identifier))))))