5139: 公司邮件

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述

Beroil公司的结构是分层的,也就是说,它可以用一棵树来表示。让我们按如下方式检查此结构的表示:


雇员::=姓名。|名称:employee1employee2,雇员。

Name::=员工姓名

也就是说,每个员工的描述包括他的姓名、冒号(:)、用逗号分隔的所有下属的描述,最后还有一个点。如果员工没有下属,则说明中不存在冒号。

例如,MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...这是记录公司结构的正确方式,其中董事MIKE有下属MAXARTEMDMITRYARTEM有一个下属,他的名字叫MIKE,就像他的老板和DMITRY的两个下属的名字一样,都叫DMITRY,就像他自己一样。

Beroil公司,每个员工只能与下属通信,因为下属不一定是直接的。让我们把一种不舒服的情况称为一个姓s的人给另一个姓s的人写信的情况。在上面给出的例子中,有两对这样的人:一对涉及MIKE,另一对涉及DMITRY(每个下属一对)。

你的任务是根据给定的公司结构,找出其中令人不适的配对数量。

The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows:
  • employee ::= name. | name:employee1,employee2, ... ,employeek.
  • name ::= name of an employee
That is, the description of each employee consists of his name, a colon (:), the descriptions of all his subordinates separated by commas, and, finally, a dot. If an employee has no subordinates, then the colon is not present in his description.
For example, line MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... is the correct way of recording the structure of a corporation where the director MIKE has subordinates MAX, ARTEM and DMITRY. ARTEM has a subordinate whose name is MIKE, just as the name of his boss and two subordinates of DMITRY are called DMITRY, just like himself.
In the Beroil corporation every employee can only correspond with his subordinates, at that the subordinates are not necessarily direct. Let's call an uncomfortable situation the situation when a person whose name is s writes a letter to another person whose name is also s. In the example given above are two such pairs: a pair involving MIKE, and two pairs for DMITRY (a pair for each of his subordinates).
Your task is by the given structure of the corporation to find the number of uncomfortable pairs in it.

Input
The first and single line contains the corporation structure which is a string of length from 1 to 1000 characters. It is guaranteed that the description is correct. Every name is a string consisting of capital Latin letters from 1 to 10 symbols in length.
Output
Print a single number − the number of uncomfortable situations in the company.
Examples
Input
MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...
Output
3
Input
A:A..
Output
1
Input
A:C:C:C:C.....
Output
6

输入格式

第一行和单行包含公司结构,这是一个长度从11000个字符的字符串。保证描述正确。每个名字都是一个由长度从110个符号的大写拉丁字母组成的字符串。

输出格式

打印一个数字——公司中不舒服情况的数量。

Input
MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...
Output
3
Input
A:A..
Output
1
Input
A:C:C:C:C.....
Output
6

输入样例 复制

MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...

输出样例 复制

3