python defaultdict(list)

>>> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
>>> d = defaultdict(list)
>>> for k, v in s:
...     d[k].append(v)
>>> d.items()
[('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])]

Here is what the above code is Doing:
1. We start with a list of tuples.
2. We create a defaultdict with a default type of list.
3. We iterate over the list of tuples.
4. For each tuple, we add the first element as a key to the defaultdict, and the second element as a value to the key’s list.
5. We print out the items in the defaultdict.

As you can see, the keys in the defaultdict are the unique first elements from each tuple, and the values are lists containing the second elements from each tuple.

Given pairs of strings, determine each pair’s similarity score. The similarity score for a pair of strings is defined as the length of the longest prefix common to both and . For example, the similarity score for the pair of strings and , is .

Given pairs of strings, find and print the number of pairs of strings with a similarity score of .

Input Format

The first line contains a single integer, , denoting the number of pairs of strings.
Each line of the subsequent lines contains two space-separated strings describing the respective values of and .


Output Format

Print the number of pairs where and share a common prefix of length .

Sample Input

hello world
hi planet
Sample Output


We have pairs to check:

and share a common prefix of length , so we print on a new line.
and share a common prefix of length , so we print on a new line.

Thus, we print as our answer.