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())
  s = {}
  for i in range(n):
      temp = input()
      s.setdefault(len(temp), [])
      s[len(temp)].append(temp)
  s2 = []
  for i, j in s.items():
      s2.append([i, j])
  s2.sort()
  ans = 0
  for i in range(len(s2)):
      for j in range(i + 1, len(s2)):
          short = s2[i][1]
          long = s2[j][1]
          short2 = {}
          long2 = {}
          for k in short:
              short2.setdefault((k[0], k[1:]), 0)
              short2[(k[0], k[1:])] += 1
          for k in long:
              temp = s2[j][0] - s2[i][0] + 1
              for l in k[:temp]:
                  long2.setdefault((l, k[temp:]), 0)
                  long2[(l, k[temp:])] += 1
          for k in short2.keys():
              if k in long2.keys():
                  ans += short2[k] * long2[k]
  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)."}]