output_description: Print the number of unordered pairs (S_i, S_j) where i \neq j and Limak can
  obtain one string from the other.
  
  * * *
input_description: Input is given from Standard Input in the following format.
  
      
      
      N
      S_1
      S_2
      \vdots
      S_N
attempt: class SparseTable:
      def __init__(self, a, func=max, one=-(10**18)):
          self.table = [a[:]]
          self.n = len(a)
          self.logn = self.n.bit_length()
          self.func = func
          self.one = one
  
          for i in map(lambda x: 1 << x, range(self.logn - 1)):
              self.table.append([])
              for j in range(self.n - i * 2 + 1):
                  self.table[-1].append(
                      self.func(self.table[-2][j], self.table[-2][j + i])
                  )
  
      def get_section(self, i, j):
          length = j - i
          log = length.bit_length() - 1
          if length <= 0:
              return self.one
          return self.func(self.table[log][i], self.table[log][j - (1 << log)])
  
  
  n = int(input())
  s = []
  for i in range(n):
      s.append(input()[::-1])
  s.sort()
  com = []
  for i in range(n - 1):
      j = 0
      for x, y in zip(s[i], s[i + 1]):
          if x != y:
              break
          j += 1
      com.append(j)
  
  mal = max(map(len, s))
  
  abc = "abcdefghijklmnopqrstuvwxyz"
  
  
  def cou(ind):
      ret = [[0] * mal]
      for i in range(n):
          ret.append([0] * mal)
          ss = 0
          for j in reversed(range(len(s[i]))):
              ss = max(ss, 1 if s[i][j] == abc[ind] else 0)
              ret[-1][j] = ss
  
      for i in range(mal):
          for j in range(n):
              ret[j + 1][i] += ret[j][i]
      return ret
  
  
  c_c = [cou(i) for i in range(26)]
  
  sp = SparseTable(com, min, 10**18)
  
  ans = 0
  for i in range(n):
      ng = -1
      ok = i
      while abs(ng - ok) > 1:
          m = (ng + ok) // 2
          if sp.get_section(m, i) >= len(s[i]) - 1:
              ok = m
          else:
              ng = m
  
      min_ok = ok
      ng = n
      ok = i
      while abs(ng - ok) > 1:
          m = (ng + ok) // 2
          if sp.get_section(i, m) >= len(s[i]) - 1:
              ok = m
          else:
              ng = m
      max_ok = ok
  
      ch = abc.index(s[i][-1])
  
      ans += c_c[ch][max_ok + 1][len(s[i]) - 1] - c_c[ch][min_ok][len(s[i]) - 1]
  
  ans -= n
  dic = {}
  for i in s:
      if i in dic:
          ans -= dic[i]
          dic[i] += 1
      else:
          dic[i] = 1
  print(ans)
  
problem_description: 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 N different strings S_1, S_2, \ldots, S_N. Among N \cdot (N-1) /
  2 pairs (S_i, S_j), in how many pairs could Limak obtain one string from the
  other?
samples: [{"input": "3\n    abcxyx\n    cyx\n    abc", "output": "1\n    \n\nThe only good pair is (abcxyx, cyx).\n\n* * *"}, {"input": "6\n    b\n    a\n    abc\n    c\n    d\n    ab", "output": "5\n    \n\nThere are five good pairs: (b, abc), (a, abc), (abc, c), (b, ab), (a, ab)."}]