Compare string - MarisaOJ: Marisa Online Judge

Compare string

Time limit: 1000 ms
Memory limit: 256 MB
Given a function f(s,t) which takes two string s and t as input. Without loss of generality that |s|≤|t|, let's say the output of the function is as follow: f(s,t)={0,if s is a prefix of t.the first position where s and t differ,otherwise. For example, f(abc,abd)=3. Given a n string Si. Calculate: ∑i=1n∑j=i+1nf(Si,Sj) ### Input - The first line contains an integer n. - The next n lines, each line contains a string Si, each string contains only lowercase letters. ### Output - Print the value. ### Constraints - 1≤n≤105. - 1≤∑|Si|≤106 ### Example Input: 4catm^atsir Output: 6