#P3376. Finding Palindromes

    ID: 2386 远端评测题 10000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>POJ Monthly--2007.09.09, Zhou Gelin, modified from POI06

Finding Palindromes

Description

A word is called a palindrome if we read from right to left is as same as we read from left to right. For example, "dad", "eye" and "racecar" are all palindromes, but "odd", "see" and "orange" are not palindromes.

Given n strings, you can generate n × n pairs of them and concatenate the pairs into single words. The task is to count how many of the so generated words are palindromes.

Input

The first line of input file contains the number of strings n. The following n lines describe each string:

The i+1-th line contains the length of the i-th string li, then a single space and a string of li small letters of English alphabet.

You can assume that the total length of all strings will not exceed 2,000,000. Two strings in different line may be the same.

Output

Print out only one integer, the number of palindromes.

3
1 a
2 ab
2 ba
5

Hint

The 5 palindromes are:

aa aba aba abba baab

Source

POJ Monthly--2007.09.09, Zhou Gelin, modified from POI06