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)

use proconio::input;

#[derive(Debug)]
struct Rational {
    int: u16,
    frac: u64, // represented in 1/1,000,000,000
}

fn to_frac(s_orig: &str) -> u64 {
    let mut s = s_orig.to_owned();
    for _ in 0 .. 9 - s.len() {
        s.push('0');
    }
    let r: u64 = s.parse().unwrap();
    return r;
}

fn parse(s: &String) -> Rational {
    let v: Vec<_> = s.split('.').collect();
    if v.len() == 1 {
        return Rational {
            int: v[0].parse().unwrap(),
            frac: 0,
        };
    }

    if v.len() != 2 {
        panic!();
    }
    let r = Rational {
        int: v[0].parse().unwrap(),
        frac: to_frac(v[1]),
    };
    return r;
}

fn is_prod_int(l: &Rational, r: &Rational) -> bool {
    let li_rf : u128 = (l.int as u128) * (r.frac as u128) * 1_000_000_000;
    let ri_lf : u128 = (r.int as u128) * (l.frac as u128) * 1_000_000_000;
    let ff    : u128 = (l.frac as u128) * (r.frac as u128);

    return (li_rf + ri_lf + ff) % 1_000_000_000_000_000_000 == 0;
}

fn main() {
    input!{
        n: usize,
    }
    let mut v: Vec<Rational> = Vec::with_capacity(n);
    let mut ints = 0;
    for _ in 0..n {
        input! {
            a: String,
        }
        let r = parse(&a);
        //println!("{:?}", r);
        v.push(r);
    }
    for i in 0..n-1 {
        for j in i+1 .. n {
            if is_prod_int(&v[i], &v[j]) {
                ints += 1;
            }
        }
    }

    println!("{}", ints);
}