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 Lua (LuaJIT 2.1.0) (judge verdict: Accepted)

local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local mfl, mce = math.floor, math.ceil

local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end

local t2, t5 = {}, {}
local t2min, t2max, t5min, t5max = 0, 0, 0, 0

local n = io.read("*n", "*l")
for i = 1, n do
  local s = io.read()
  local c2, c5 = 0, 0
  if s:find("%.") then
    local x, y = s:match("(%d+)%.(%d+)")
    x = tonumber(x)
    local dig = #y
    local denom = 1
    for j = 1, #y do
      denom = denom * 10
    end
    y = tonumber(y)
    local gcd = getgcd(denom, y)
    denom = mfl(denom / gcd)
    y = mfl(y / gcd)
    local a = x * denom + y
    local b = denom

    while a % 2 == 0 do
      a = mfl(a / 2)
      c2 = c2 + 1
    end
    while a % 5 == 0 do
      a = mfl(a / 5)
      c5 = c5 + 1
    end
    while b % 2 == 0 do
      b = mfl(b / 2)
      c2 = c2 - 1
    end
    while b % 5 == 0 do
      b = mfl(b / 5)
      c5 = c5 - 1
    end
  else
    local x = tonumber(s)
    while x % 2 == 0 do
      x = mfl(x / 2)
      c2 = c2 + 1
    end
    while x % 5 == 0 do
      x = mfl(x / 5)
      c5 = c5 + 1
    end
  end
  t2[i] = c2
  t5[i] = c5
  t2min = mmi(t2min, c2)
  t2max = mma(t2max, c2)
  t5min = mmi(t5min, c5)
  t5max = mma(t5max, c5)
end
local t = {}
local wid2 = t2max - t2min + 1
local wid5 = t5max - t5min + 1
local sz = wid2 * wid5
for i = 1, sz do
  t[i] = 0
end
local ret = 0
for i = 1, n do
  local c2, c5 = t2[i], t5[i]
  local need2, need5 = mma(t2min, -c2), mma(t5min, -c5)
  for j = need2, t2max do
    for k = need5, t5max do
      local idx = (j - t2min) * wid5 + (k - t5min + 1)
      ret = ret + t[idx]
    end
  end
  do
    local idx = (c2 - t2min) * wid5 + (c5 - t5min + 1)
    t[idx] = t[idx] + 1
  end
end
print(ret)