Problem:
Score : 300 points

Problem Statement

You are given N real values A_1, A_2, \ldots, A_N.
Compute the number of pairs of indices (i, j)
such that i < j and the product A_i \cdot A_j is integer.

Constraints

2 \leq N \leq 200\,000

0 < A_i < 10^4

A_i is given with at most 9 digits after the decimal.

Input

Input is given from Standard Input in the following format.

N
A_1
A_2
\vdots
A_N

Output

Print the number of pairs with integer product A_i \cdot A_j (and i < j).

Sample Input 1

5
7.5
2.4
17.000000001
17
16.000000000

Sample Output 1

3

There are 3 pairs with integer product:

7.5 \cdot 2.4 = 18

7.5 \cdot 16 = 120

17 \cdot 16 = 272

Sample Input 2

11
0.9
1
1
1.25
2.30000
5
70
0.000000001
9999.999999999
0.999999999
1.000000001

Sample Output 2

8

Solution in Rust (1.42.0) (judge verdict: Time Limit Exceeded)

// 定数定義
static DEC_CONST: u64 = 1000000000;
static DEC_CONST_2: u64 = DEC_CONST * DEC_CONST;

fn main() {
    // 変数宣言
    let n: u32;
    let mut a_ip: Vec<u64>; // 整数部
    let mut a_dp: Vec<u64>; // 小数部（10^9倍済）
                            // 入力の処理
    let mut buf: String = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    n = buf.trim().parse().ok().unwrap();
    a_ip = Vec::<u64>::with_capacity(n as usize);
    a_dp = Vec::<u64>::with_capacity(n as usize);
    for _ in 0..n {
        let tmp_float: f64;
        buf = String::new();
        std::io::stdin().read_line(&mut buf).ok();
        tmp_float = buf.trim().parse().ok().unwrap();
        let tmp: Vec<&str> = buf.trim().split('.').collect();
        let val1: u64 = tmp[0].parse().ok().unwrap();
        let val2: u64 = ((tmp_float - (val1 as f64)) * (DEC_CONST as f64)).round() as u64;
        a_ip.push(val1);
        a_dp.push(val2);
    }
    // 愚直カウント
    let mut counter: u32 = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            // DEC_CONST ^2 が乗じられた小数部。制限：18桁
            let tmp1 = a_dp[i as usize] * a_dp[j as usize];
            // DEC_CONST ^2 が乗じられた小数部の片方。制限：14桁→剰余演算で5桁→14桁まで拡張
            let tmp2 = (a_ip[i as usize] * a_dp[j as usize] % DEC_CONST) * DEC_CONST;
            // DEC_CONST ^2 が乗じられた小数部の片方。制限：14桁→剰余演算で5桁→14桁まで拡張
            let tmp3 = (a_ip[j as usize] * a_dp[i as usize] % DEC_CONST) * DEC_CONST;
            // すべて足して、DEC_CONST ^2 の剰余を取る。この値が0より大ならカウント。
            let tmp_total_dp = (tmp1 + tmp2 + tmp3) % DEC_CONST_2;
            if tmp_total_dp == 0 {
                counter += 1;
            }
        }
    }
    println!("{}", counter);
}