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.

<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.

Examples

Input

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


Output

3


Input

A:A..


Output

1


Input

A:C:C:C:C.....


Output

6
import java.io.*;
import java.util.*;

public class C
{
	String line;
	StringTokenizer inputParser;
	BufferedReader is;
	FileInputStream fstream;
	DataInputStream in;
	
	void openInput(String file)
	{

		if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
		else
		{
			try{
		
				
			fstream = new FileInputStream(file);
			in = new DataInputStream(fstream);
			is = new BufferedReader(new InputStreamReader(in));
			}catch(Exception e)
			{
				System.err.println(e);
			}
		}

	}
	
	void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}	
		
	}
	
	int NextInt()
	{
		String n = inputParser.nextToken();
		int val = Integer.parseInt(n);
		
		//System.out.println("I read this number: " + val);
		return val;
	}
	
	String NextString()
	{
		String n = inputParser.nextToken();
		return n;
	}
	
	void closeInput()
	{
		try {
			is.close();
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
			
	}
	
	
	public static void main(String [] argv)
	{
		String filePath=null;
		if(argv.length>0)filePath=argv[0];
		C c = new C(filePath);
	}
	long [] f = new long[70];
	
	public C(String inputFile)
	{
		long ret=0;
		openInput(inputFile);
		
		readNextLine();
		int N=line.length();
		ArrayList <Worker> list = new ArrayList <Worker>();
		
		
		f[0]=1;
		for(int i=1; i<70; i++)f[i]=i*f[i-1];
		//System.out.println(f[69]);
			
		String n="";
		Worker up=null;
		String el=":.,";
		for(int i=0; i<N; i++)
		{
			if(el.indexOf(line.charAt(i))>-1)
			{
				if(n.length()>0)
				{
					Worker w=new Worker (n, up);
				
					list.add(w);
					up=w;
					n="";
				}
				
				switch(line.charAt(i))
				{
					case ':':
						break;
					case '.':
						up=up.up;
						break;
					case ',':
						break;
				}
				
			}
			else n+=line.charAt(i);
		
		}
		
		for(int i=0; i<list.size(); i++)
		{
			//long nn=list.get(i).getNum(list.get(i).name);
			//System.out.println(list.get(i).name+" "+nn);
			ret+=list.get(i).getNum(list.get(i).name);
		}
		//ret/=2;
		
		System.out.println(ret);
		
        
        closeInput();
	}

	class Worker
	{
		Worker up;
		ArrayList <Worker> down;
		String name;
		long myNum=-1;
		
		
		Worker(String n, Worker chef)
		{
			up=chef;
			name=n;
			down = new ArrayList<Worker>();
			if(chef!=null)chef.addSub(this);
		}
		
		void addSub(Worker w)
		{
			down.add(w);
		}
		
		long getNum(String s)
		{
			//if(myNum>-1)return myNum;
			long ret=0;
			for(int i=0; i<down.size(); i++)
			{
				if(down.get(i).name.compareTo(s)==0)
				{
					ret++;
					
				}
				ret+=down.get(i).getNum(s);
			}
			myNum=ret;
			return ret;
		}
	}

	
}

