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: n = int(input())
  ss = [input() for i in range(n)]
  m = dict()
  
  
  def chi(x):
      return ord(x) - ord("a")
  
  
  def cha(x):
      return chr(97 + x)
  
  
  # それぞれの文字列のi文字目までの種類
  # set→整数
  check = [[0 for j in range(len(ss[i]))] for i in range(n)]
  for i in range(n):
      check[i][0] = 1 << chi(ss[i][0])
      for j in range(1, len(ss[i])):
          check[i][j] = check[i][j - 1] ^ (1 << chi(ss[i][j]))
  # m[s][i]:0or1
  for i in range(n):
      if ss[i][1:] not in m:
          m[ss[i][1:]] = [0] * 26
          m[ss[i][1:]][chi(ss[i][0])] += 1
      else:
          m[ss[i][1:]][chi(ss[i][0])] += 1
  ans = 0
  for i in range(n):
      s = ""
      l = len(ss[i])
      for j in range(l, 1, -1):
          if j != l:
              s = ss[i][j] + s
          for k in range(26):
              if s in m:
                  if m[s][k]:
                      if (check[i][j - 1] >> k) & 1:
                          ans += 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)."}]