Given strings consisting of lowercase letters. It is guaranteed that these strings are sorted in non-decreasing order of length, i.e. .
For any two different strings and with , define , which means the new string obtained by concatenating and in order, with in front and behind.
We define a function , where is a string of length . The value of is the number of positive integers () satisfying the following condition:
- The first characters of string are exactly the same as the last characters of . That is, .
Your task is to compute the sum of over all valid pairs , that is: