output_description: Print one integer — the sum over ((A_i \cdot A_j) \bmod P).
  
  * * *
input_description: Input is given from Standard Input in the following format.
  
      
      
      N
      A_1 A_2 \cdots A_N
attempt: import sys
  
  input = sys.stdin.readline
  (N,) = map(int, input().split())
  S = []
  for _ in range(N):
      s = input().strip()
      S.append(s)
  S.sort(key=lambda x: len(x))
  D = dict()
  dd = set()
  R = 0
  for s in S:
      l = len(s)
      d = [0] * 26
      for c in dd:
          d[c] += 1
      mm = 0
      tmp = 0
      for i in range(l - 1, -1, -1):
          cc = ord(s[i]) - 97
          tmp = 26 * tmp + cc
          R += d[cc]
          d[cc] = 0
          if tmp in D:
              for c in D[tmp]:
                  d[c] += 1
          if i == 0:
              f = cc
          if i == 1:
              nn = tmp
          mm += 1
      if l != 1:
          if nn not in D:
              D[nn] = set()
          D[nn].add(f)
      else:
          dd.add(f)
  print(R)
  
problem_description: Statement
  
  Let’s take a prime P = 200\,003. You are given N integers A_1, A_2, \ldots,
  A_N. Find the sum of ((A_i \cdot A_j) \bmod P) over all N \cdot (N-1) / 2
  unordered pairs of elements (i < j).
  
  Please note that the sum isn't computed modulo P.
samples: [{"input": "4\n    2019 0 2020 200002", "output": "474287\n    \n\nThe non-zero products are:\n\n  * 2019 \\cdot 2020 \\bmod P = 78320\n  * 2019 \\cdot 200002 \\bmod P = 197984\n  * 2020 \\cdot 200002 \\bmod P = 197983\n\nSo the answer is 0 + 78320 + 197984 + 0 + 0 + 197983 = 474287.\n\n* * *"}, {"input": "5\n    1 1 2 2 100000", "output": "600013"}]