Chat Server's Outgoing Traffic
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
题目描述
Polycarp正在开发一个名为“Polychat”的新项目。沿袭IT的现代趋势,他决定这个项目也应该包含聊天。为了实现这个目标,Polycarp在他的笔记本电脑前花费了数个小时,实现了一个聊天服务器,可以处理三种类型的命令:
- 将人添加到聊天中(“Add”命令)。
- 将人从聊天中删除(“Remove”命令)。
- 将信息从发送者发送给当前聊天中的所有人,包括发送信息的人(“Send”命令)。
现在Polycarp希望找出服务器在处理特定一组命令时产生的出站流量。
Polycarp知道聊天服务器在处理“Add”和“Remove”命令时不会发送任何流量。当处理“Send”命令时,服务器将向聊天的每个参与者发送l字节的信息,其中l是消息的长度。
由于Polycarp时间有限,他请求您帮助解决此问题。
输入文件不超过100个命令,每个命令单独在一行中。每行不超过100个字符。命令的格式如下:
- “Add”命令为+<name>。
- “Remove”命令为-<name>。
- “Send”命令为<sender_name>:<message_text>。
<name>和<sender_name>是拉丁字母和数字的非空序列。 <message_text>可以包含字母、数字和空格,但不能以空格开头或结尾。 <message_text>可以是空行。
保证输入数据是正确的,即如果该名称的人员已经在聊天中,则不会有“Add”命令,如果没有该名称的人员在聊天中,则不会有“Remove”命令,等等。
所有名称区分大小写。
输出一个数字——问题的答案。
Description
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:
- Include a person to the chat ('Add' command).
- Remove a person from the chat ('Remove' command).
- Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command).
Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.
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.
As Polycarp has no time, he is asking for your help in solving this problem.
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:
- +<name> for 'Add' command.
- -<name> for 'Remove' command.
- <sender_name>:<message_text> for 'Send' command.
<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.
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.
All names are case-sensitive.
Print a single number — answer to the problem.
Input
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:
- +<name> for 'Add' command.
- -<name> for 'Remove' command.
- <sender_name>:<message_text> for 'Send' command.
<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.
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.
All names are case-sensitive.
Output
Print a single number — answer to the problem.
Samples
+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate
9
+Mike
-Mike
+Mike
Mike:Hi I am here
-Mike
+Kate
-Kate
14