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 Rust (1.42.0) (judge verdict: Runtime Error)

// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};
use std::collections::{BTreeMap, HashMap};

#[fastout]
fn main() {
    input! {
        n: usize,
        s_str: [String; n],
    }
    let mut s: Vec<String> = Vec::new();
    for si in s_str {
        s.push(si.chars().rev().collect());
    }
    s.sort_unstable_by_key(|x| x.len());
    let mut ans: u64 = 0;
    let mut already_seen: HashMap<&str, Vec<bool>> = HashMap::new();
    for i in 1..=n {
        let mut nowstr: String = s[i - 1].clone();
        let nownagasa = nowstr.len();
        let mut have_in_prefix: Vec<bool> = vec![false; 26];
        let chars_table = vec![
            'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
            'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        ];
        let saishono = (nowstr.pop().unwrap() as usize) - ('a' as usize);
        have_in_prefix[saishono] = true;
        for _j in 1..nownagasa {
            have_in_prefix[(nowstr.pop().unwrap() as usize) - ('a' as usize)] = true;
            if let Some(atable) = already_seen.get(nowstr.as_str()) {
                for k in 0..26 {
                    if !have_in_prefix[k as usize] {
                        continue;
                    }
                    nowstr.push(chars_table[k]);
                    if atable[k] {
                        ans += 1;
                    }
                    nowstr.pop();
                }
            }
        }
        let nowstr2 = s[i - 1].as_str();
        let thetable = already_seen
            .entry(&nowstr2[0..nowstr2.len() - 1])
            .or_insert(vec![false; 26]);
        thetable[saishono] = true;
    }
    println!("{}", ans);
}