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

import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start(); 
	}

	BufferedReader in;
	PrintWriter out;
	
	StringTokenizer tok;
	Item tree;

	void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		
		tok = new StringTokenizer(in.readLine(), ":.,", true);
		tree = parseEmployee();
//		print(tree);
		out.println(proc(tree));
		out.close();
	}
	
	void print(Item node) {
		print(node, 0);
	}
	
	void print(Item node, int offset) {
		for (int i = 0; i < offset; i++)
			out.print(' ');
		out.println(node.name);
		for (Item child : node.children)
			print(child, offset + 2);
	}
	
	int proc(Item node) {
		int ret = 0;
		for (Item child : node.children)
			ret += proc(child) + calc(child, node.name);
		return ret;
	}

	int calc(Item node, String name) {
		int ret = node.name.equals(name) ? 1 : 0;
		for (Item child : node.children)
			ret += calc(child, name); 
		return ret;
	}

	Item parseEmployee() {
		Item ret = new Item(tok.nextToken());
		while (!tok.nextToken().equals("."))
			ret.addChild(parseEmployee());
		return ret;
	}

	class Item {
		String name;
		List<Item> children = new ArrayList<Main.Item>(10);
		
		Item(String name) {
			this.name = name;
		}
		
		void addChild(Item child) {
			children.add(child);
		}
		
		@Override
		public String toString() {
			return name;
		}
	}
}
