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 PHP (7.4.4) (judge verdict: Wrong Answer)

<?php
list($n) = ints();
$p = new Prime(25);
$p->makeTable();
for ($i = 0; $i < $n; ++$i) {
    list($a) = strs();
    $t = explode('.', $a);
    $t[1] = str_pad($t[1] ?? '0', 9, '0', STR_PAD_RIGHT);
    $a = $t[0] * 10 ** 9 + $t[1];
    $f = $p->factor($a);
    $f2[] = $f[2] ?? 0;
    $f5[] = $f[5] ?? 0;
}
array_multisort($f2, SORT_ASC, $f5, SORT_ASC);
$ans = 0;
for ($i = 0; $i < $n; ++$i) ++$cusum[min(18, $f2[$i])][min(17, $f5[$i])];
for ($i = 18; $i >= 0; --$i) {
    for ($j = 17; $j >= 0; --$j) {
        $cusum[$i][$j] += $cusum[$i][$j + 1];
    }
}
for ($j = 18; $j >= 0; --$j) {
    for ($i = 17; $i >= 0; --$i) {
        $cusum[$i][$j] += $cusum[$i + 1][$j];
    }
}
$ans = 0;
for ($i = 0; $i < $n; ++$i) {
    $s2 = max(0, 18 - $f2[$i]);
    $s5 = max(0, 18 - $f5[$i]);
    $ans += $cusum[$s2][$s5];
    if ($f2[$i] >= $s2 && $f5[$i] >= $s5) --$ans;
}
echo $ans / 2;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 素数関係
class Prime
{
    private $n;
    private $table; // 素数の添字にtrueが格納された配列

    function __construct($n)
    {
        $this->n = $n;
        $this->makeTable();
    }

    function makeTable()
    {
        $n = $this->n;
        $table = array_fill(2, $n - 1, true);
        $rn = (int) floor(sqrt($n));
        for ($i = 2; $i <= $rn; $i++) {
            if (!isset($table[$i])) continue;
            for ($j = 2 * $i; $j <= $n; $j += $i) {
                unset($table[$j]);
            }
        }
        $this->table = $table;
    }

    // 素数
    function primes()
    {
        return array_keys($this->table);
    }

    function table()
    {
        return $this->table;
    }

    // 素数判定
    function isPrime($x)
    {
        return isset($this->table[$x]);
    }

    // 素因数分解
    function factor($x)
    {
        $res = [];
        if ($x === 1) return $res;
        $primes = $this->primes();
        foreach ($primes as $prime) {
            while ($x % $prime === 0) {
                if (isset($res[$prime])) $res[$prime]++;
                else $res[$prime] = 1;
                $x /= $prime;
            }
        }
        if ($x > 1) {
            if (isset($res[$x])) $res[$x]++;
            else $res[$x] = 1;
        }
        return $res;
    }
}