Score : 800 points
Problem Statement
Let’s take a prime P=200003.
You are given N integers A1,A2,…,AN.
Find the sum of ((Ai⋅Aj)modP) over all N⋅(N−1)/2 unordered pairs of elements (i<j).
Please note that the sum isn't computed modulo P.
Constraints
- 2≤N≤200000
- 0≤Ai<P=200003
- All values in input are integers.
Input is given from Standard Input in the following format.
N
A1 A2 ⋯ AN
Output
Print one integer — the sum over ((Ai⋅Aj)modP).
4
2019 0 2020 200002
474287
The non-zero products are:
- 2019⋅2020modP=78320
- 2019⋅200002modP=197984
- 2020⋅200002modP=197983
So the answer is 0+78320+197984+0+0+197983=474287.
5
1 1 2 2 100000
600013