VPALIN - Finding Palindromes

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


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

hide comments
2013-09-01 19:12:18 lifeofpie
WA(16) plz provide some test case ...
2013-08-30 00:49:20 Ashutosh Singla
WA please help ..
2011-12-19 10:00:07 BOND
very strict time limit..
2010-12-29 12:34:57 :D
you are right:
"bbb" => "bbbb"
2010-12-28 18:01:22 Kush Sharma
how is "bbb" possible..?
2010-06-04 16:30:16 Tamilselvan
how bbb occurs on pairing either bbbb oly can occur isnt it??
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.