Problem:
Score : 800 points

Problem 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.

Constraints

2 \leq N \leq 200\,000

0 \leq A_i < P = 200\,003

All values in input are integers.

Input

Input is given from Standard Input in the following format.

N
A_1 A_2 \cdots A_N

Output

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

Sample Input 1

4
2019 0 2020 200002

Sample Output 1

474287

The non-zero products are:

2019 \cdot 2020 \bmod P = 78320

2019 \cdot 200002 \bmod P = 197984

2020 \cdot 200002 \bmod P = 197983

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

Sample Input 2

5
1 1 2 2 100000

Sample Output 2

600013

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

// FFT部分はtsutajさんのコードからコピペhttps://atcoder.jp/contests/atc001/submissions/2739303

#include <cassert>
#include <algorithm>
#include <cctype>
#include <complex>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <tuple>
#include <typeinfo>
#include <unordered_set>
#include <unordered_map>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REPD(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define PB(e) push_back(e)
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}

// tsutajさんのコードからコピペhttps://atcoder.jp/contests/atc001/submissions/2739303
// https://atcoder.jp/contests/atc001/submissions/2739303

using Complex = complex<double>;
vector<Complex> dft(vector<Complex> A, int N, int sgn = 1) {
    if(N == 1) return A;
 
    vector<Complex> F(N / 2), G(N / 2);
    for(int i=0; i<N/2; i++) {
        F[i] = A[2 * i + 0];
        G[i] = A[2 * i + 1];
    }
 
    F = dft(F, N / 2, sgn);
    G = dft(G, N / 2, sgn);
 
    Complex zeta(cos(2.0 * M_PI / N), sin(2.0 * M_PI / N) * sgn);
    Complex pow_zeta = 1;
 
    for(int i=0; i<N; i++) {
        A[i] = F[i % (N / 2)] + pow_zeta * G[i % (N / 2)];
        pow_zeta *= zeta;
    }
    return A;
}
 
vector<Complex> inv_dft(vector<Complex> A, int N) {
    A = dft(A, N, -1);
    for(int i=0; i<N; i++) {
        A[i] /= N;
    }
    return A;
}
 
vector<Complex> multiply(vector<Complex> A, vector<Complex> B) {
    int sz = A.size() + B.size() + 1;
    int N = 1; while(N < sz) N *= 2;
 
    A.resize(N), B.resize(N);
    A = dft(A, N);
    B = dft(B, N);
 
    vector<Complex> F(N);
    for(int i=0; i<N; i++) {
        F[i] = A[i] * B[i];
    }
    return inv_dft(F, N);
}

const int P = 200003;

int main(int argc, char *argv[]) {
  int pow2[P * 2];
  pow2[0] = 1;
  unordered_map<int, int> num2coef;
  REP(i, P * 2 - 1) {
    if (i < P - 1) {
      num2coef[pow2[i]] = i;
    }
    pow2[i + 1] = (pow2[i] * 2) % P;
  }
  int N;
  cin >> N;
  vector<Complex> vec(P);
  vector<int> nums;
  REP(i, N) {
    int v;
    cin >> v;
    if (v > 0) {
      nums.push_back(v);
      vec[num2coef[v]] = Complex(1);
    }
  }

  vector<Complex> pol = multiply(vec, vec);
  ll res = 0;
  REP(i, pol.size()) {
    if (i < P * 2) {
      res += ll(pol[i].real() + 0.5) * pow2[i];
    }
  }

  REP(i, nums.size()) {
    res -= ll(nums[i]) * nums[i] % P;
  }
  cout << res / 2 << endl;
}