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: import sys
  
  input = sys.stdin.readline
  
  N = int(input())
  S = [input().strip() for i in range(N)]
  S.sort(key=len)
  
  VLIST = [[set() for j in range(len(S[i]))] for i in range(N)]
  
  for i in range(N):
      for j in range(len(S[i])):
          VLIST[i][j] = VLIST[i][j - 1] | {S[i][j]}
  
  # ing木
  
  Next_node_id = [[-1] * 26]  # "a"～"z"それぞれについて、対応する次のノードのid
  Parent_id = [-1]  # 親ノード
  End = [[]]  # そのノードを終端とするStringがあるか
  
  ANS = 0
  
  Nodes_id = 1
  for i in range(N):
      S2 = S[i]
      L = len(S2)
  
      NOW = 0
      for j in range(L - 1, -1, -1):
          for s in End[NOW]:
              if s in VLIST[i][j]:
                  ANS += 1
  
          if j == 0:
              End[NOW].append(S2[0])
              continue
  
          NEXT = ord(S2[j]) - 97
  
          if Next_node_id[NOW][NEXT] == -1:  # Nodeを追加する場合
              Next_node_id[NOW][NEXT] = Nodes_id
  
              Next_node_id.append([-1] * 26)
              Parent_id.append(NOW)
              End.append([])
  
              NOW = Nodes_id
              Nodes_id += 1
  
          else:  # 追加しない場合
              NOW = Next_node_id[NOW][NEXT]
  
  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)."}]