#agc047b. [agc047_b]First Second

[agc047_b]First Second

Problem Statement

Limak can repeatedly remove one of the first two characters of a string, for example $abcxyx \\rightarrow acxyx \\rightarrow cxyx \\rightarrow cyx$.

You are given NN different strings S1,S2,ldots,SNS_1, S_2, \\ldots, S_N. Among Ncdot(N1)/2N \\cdot (N-1) / 2 pairs (Si,Sj)(S_i, S_j), in how many pairs could Limak obtain one string from the other?

Constraints

  • 2leqNleq200,0002 \\leq N \\leq 200\\,000
  • SiS_i consists of lowercase English letters a-z.
  • SineqSjS_i \\neq S_j
  • 1leqSi1 \\leq |S_i|
  • S1+S2+ldots+SNleq106|S_1| + |S_2| + \\ldots + |S_N| \\leq 10^6

Input

Input is given from Standard Input in the following format.

NN S1S_1 S2S_2 vdots\\vdots SNS_N

Output

Print the number of unordered pairs (Si,Sj)(S_i, S_j) where ineqji \\neq j and Limak can obtain one string from the other.


Sample Input 1

3
abcxyx
cyx
abc

Sample Output 1

1

The only good pair is (abcxyx,cyx)(abcxyx, cyx).


Sample Input 2

6
b
a
abc
c
d
ab

Sample Output 2

5

There are five good pairs: (b,abc)(b, abc), (a,abc)(a, abc), (abc,c)(abc, c), (b,ab)(b, ab), (a,ab)(a, ab).