#AGC047C. [AGC047C] Product Modulo

[AGC047C] Product Modulo

Score : 800800 points

Problem Statement

Let’s take a prime P=200003P = 200\,003. You are given NN integers A1,A2,,ANA_1, A_2, \ldots, A_N. Find the sum of ((AiAj)modP)((A_i \cdot A_j) \bmod P) over all N(N1)/2N \cdot (N-1) / 2 unordered pairs of elements (i<ji < j).

Please note that the sum isn't computed modulo PP.

Constraints

  • 2N2000002 \leq N \leq 200\,000
  • 0Ai<P=2000030 \leq A_i < P = 200\,003
  • All values in input are integers.

Input

Input is given from Standard Input in the following format.

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print one integer — the sum over ((AiAj)modP)((A_i \cdot A_j) \bmod P).

4
2019 0 2020 200002
474287

The non-zero products are:

  • 20192020modP=783202019 \cdot 2020 \bmod P = 78320
  • 2019200002modP=1979842019 \cdot 200002 \bmod P = 197984
  • 2020200002modP=1979832020 \cdot 200002 \bmod P = 197983

So the answer is 0+78320+197984+0+0+197983=4742870 + 78320 + 197984 + 0 + 0 + 197983 = 474287.

5
1 1 2 2 100000
600013