Codeforces Beta Round 52 (Div. 2)
C
Corporation Mail
Codeforces
1700
原题
← BD →
翻译中…

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*$:$*employee*_{1}$,$*employee*_{2}$, ... ,$*employee*_{*k*}$.
  • $*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.

翻译中…

image

翻译中…

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.

翻译中…

样例

Input #1
MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...
Output #1
3
InputCopy OutputCopy
Input #2
A:A..
Output #2
1
InputCopy OutputCopy
Input #3
A:C:C:C:C.....
Output #3
6
InputCopy OutputCopy
题目信息
题号
56C
时间限制
2 s
内存限制
256 MB
标签
数据结构
表达式解析
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。