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::*;
use proconio::marker::*;

// A からBが得られるには
// Aの末尾|B| - 1 文字がB[1..] と等しい
// かつAの末尾|B| - 1 文字以外の文字の中に B[0] がある
// O(N^2)
// 文字が長いやつからTrieに挿入、戻る時に存在する文字をbitで覚えてカウンタ更新
//

type Link = Option<Box<Node>>;

const F: usize = 26;

#[derive(Default)]
struct Node {
    cnt: [u32; F],
    next: [Link; F],
}

fn insert(node: &mut Link, s: &[u8], ans: &mut usize) -> usize {
    if node.is_none() {
        *node = Some(Box::new(Node::default()));
    }
    let node = node.as_mut().unwrap();
    if s.len() == 0 {
        0
    } else {
        let k = (s[0] - b'a') as usize;
        let mut mask = insert(&mut node.next[k], &s[1..], ans);
        if s.len() == 1 {
            *ans += node.cnt[k] as usize;
        }
        mask |= 1 << k;
        for (i, c) in node.cnt.iter_mut().enumerate() {
            *c += ((mask >> i) & 1) as u32;
        }
        mask
    }
}

fn run() {
    input! {
        n: usize,
        mut s: [Bytes; n],
    }
    s.sort_by_key(|s| s.len());
    let mut root = None;
    let mut ans = 0;
    for s in s.iter_mut().rev() {
        s.reverse();
        insert(&mut root, s, &mut ans);
    }
    println!("{}", ans);
}

fn main() {
    let stack_size = 104_857_600 << 2; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| run()).unwrap().join().unwrap();
}