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: Runtime Error)

use proconio::input;
// dbg {{{
#[allow(dead_code)]
mod dbg {
    use std::fmt::{Debug, Formatter};

    #[derive(Clone)]
    pub struct Tabular<'a, T: Debug>(pub &'a [Vec<T>]);
    impl<'a, T: Debug> Debug for Tabular<'a, T> {
        fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
            for i in 0..self.0.len() {
                writeln!(f, "{:2} | {:?}", i, &self.0[i])?;
            }
            Ok(())
        }
    }

    #[derive(Clone)]
    pub struct BooleanTable<'a>(pub &'a [Vec<bool>]);
    impl<'a> Debug for BooleanTable<'a> {
        fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
            for i in 0..self.0.len() {
                writeln!(f, "{:2} | {:?}", i, BooleanSlice(&self.0[i]))?;
            }
            Ok(())
        }
    }

    #[derive(Clone)]
    pub struct BooleanSlice<'a>(pub &'a [bool]);
    impl<'a> Debug for BooleanSlice<'a> {
        fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
            write!(
                f,
                "{}",
                self.0
                    .iter()
                    .map(|&b| if b { '#' } else { '.' })
                    .collect::<String>()
            )?;
            Ok(())
        }
    }
}
// }}}
use dbg::Tabular;

fn main() {
    input!(n: usize);
    let values = (0..n)
        .map(|_| {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let s = s.trim_end().to_owned();
            let s = s.split('.').collect::<Vec<_>>();
            let a = s[0].parse::<u64>().unwrap();
            let b = s
                .get(1)
                .map(|s| {
                    let mut s = s.to_string();
                    let len = s.len();
                    s.extend(std::iter::repeat('0').take(9 - len));
                    s.parse::<u64>().unwrap()
                })
                .unwrap_or(0);

            let mut c = a * 1_000_000_000 + b;

            let mut p = 0;
            let mut q = 0;
            while c % 2 == 0 {
                c /= 2;
                p += 1;
            }
            while c % 5 == 0 {
                c /= 5;
                q += 1;
            }
            (p, q)
        })
        .collect::<Vec<(usize, usize)>>();

    const SIZE: usize = 20;

    let mut g = vec![vec![0; SIZE]; SIZE];
    for &(p, q) in &values {
        g[p][q] += 1;
    }
    for i in (0..SIZE).rev() {
        for j in (0..SIZE).rev() {
            if i != SIZE - 1 {
                g[i][j] += g[i + 1][j];
            }
            if j != SIZE - 1 {
                g[i][j] += g[i][j + 1];
            }
            if i != SIZE - 1 && j != SIZE - 1 {
                g[i][j] -= g[i + 1][j + 1];
            }
        }
    }

    let mut ans = 0u64;
    for &(p, q) in &values {
        ans += g[18 - p][18 - q];
    }
    for &(p, q) in &values {
        if 9 <= p && 9 <= q {
            ans -= 1;
        }
    }
    assert_eq!(ans % 2, 0);
    ans /= 2;
    println!("{}", ans);
}