VPALIN - Finding Palindromes

no tags 

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

Example

Input:
3
1 a
2 bb
2 aa


Output:
5

Explanation

The 5 palindromes are: aa aaa aaa bbbb aaaa


hide comments
lifeofpie: 2013-09-01 19:12:18

WA(16) plz provide some test case ...

Ashutosh Singla: 2013-08-30 00:49:20

WA please help ..

BOND: 2011-12-19 10:00:07

very strict time limit..

:D: 2010-12-29 12:34:57

you are right:
"bbb" => "bbbb"

Kush Sharma: 2010-12-28 18:01:22

how is "bbb" possible..?

Tamilselvan: 2010-06-04 16:30:16

how bbb occurs on pairing either bbbb oly can occur isnt it??


Added by:Phenomenal
Date:2009-02-15
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:POI 2006