codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

5A.md (2169B)


      1 Source: https://codeforces.com/problemset/problem/5/A
      2 
      3 A. Chat Server's Outgoing Traffic
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 64 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
     22 
     23 * Include a person to the chat ('Add' command).
     24 * Remove a person from the chat ('Remove' command).
     25 * Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command).
     26 
     27 Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.
     28 
     29 Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends *l* bytes to each participant of the chat, where *l* is the length of the message.
     30 
     31 As Polycarp has no time, he is asking for your help in solving this problem.
     32 
     33 Input
     34 
     35 Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
     36 
     37 * +<name> for 'Add' command.
     38 * -<name> for 'Remove' command.
     39 * <sender_name>:<message_text> for 'Send' command.
     40 
     41 <name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.
     42 
     43 It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.
     44 
     45 All names are case-sensitive.
     46 
     47 Output
     48 
     49 Print a single number — answer to the problem.
     50 
     51 Examples
     52 
     53 Input
     54 
     55 ```
     56 +Mike  
     57 Mike:hello  
     58 +Kate  
     59 +Dmitry  
     60 -Dmitry  
     61 Kate:hi  
     62 -Kate
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 9
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 +Mike  
     75 -Mike  
     76 +Mike  
     77 Mike:Hi   I am here  
     78 -Mike  
     79 +Kate  
     80 -Kate
     81 ```
     82 
     83 Output
     84 
     85 ```
     86 14
     87 ```