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 Ruby (2.7.1) (judge verdict: Wrong Answer)

require 'prime'
memo = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]
n = gets.to_i
nums = []
n.times do
  # 小数点の前、後ろで分ける
  former, latter = gets.chomp.split('.')
  latter = '' unless latter
  latter_size = latter.size
  # 分数で表した時、分母に含まれる 10 の数
  bunbo_10 = latter_size
  bunshi = former.to_i * memo[latter_size] + latter.to_i
  divisors = Prime.prime_division(bunshi)
  twos = divisors.find { |array| array[0] == 2 }
  # 分子に含まれる 2 の数
  bunshi_2 = twos ? twos[1] : 0
  fives = divisors.find { |array| array[0] == 5 }
  # 分子に含まれる 5 の数
  bunshi_5 = fives ? fives[1] : 0
  min = bunshi_2
  min = bunshi_5 if min > bunshi_5
  bunshi_2 -= min
  bunshi_5 -= min
  bunbo_10 -= min
  # [分母に含まれる 10 の数、分子に含まれる 2 の数, 分子に含まれる 5 の数]
  # 7.5 は [1, 0, 2] となる
  nums << [bunbo_10, bunshi_2, bunshi_5]
end

# 分子に 2 を含む数字を bunbo_10 ごとにメモ
# bunbo_10[-4, -3, ....... 8, 9]
# bunshi_2[0, 1, 2 .... 43, 44] の累積和とする（右から）
memo_inc_2 = Array.new(14) { Array.new(45, 0) }

# 分子に 5 を含む数字を bunbo_10 ごとにメモ
# bunbo_10[-4, -3, ....... 8, 9]
# bunshi_5[0, 1, 2 .... 43, 44] の累積和とする（右から）
memo_inc_5 = Array.new(14) { Array.new(45, 0) }

# どちらも含まない数字のメモ
# bunbo_10[-4, -3, ... 8, 9] の累積和とする（左から）
memo_inc_0 = Array.new(14, 0)

nums.each do |bunbo_10, bunshi_2, bunshi_5|
  if bunshi_2 > 0
    memo_inc_2[bunbo_10 + 4][bunshi_2] += 1
  elsif bunshi_5 > 0
    memo_inc_5[bunbo_10 + 4][bunshi_5] += 1
  else
    memo_inc_0[bunbo_10 + 4] += 1
  end
end

# 累積和を算出
14.times do |row|
  43.downto(0) do |i|
    memo_inc_2[row][i] += memo_inc_2[row][i + 1]
    memo_inc_5[row][i] += memo_inc_5[row][i + 1]
  end
end
1.upto(13) do |i|
  memo_inc_0[i] += memo_inc_0[i - 1]
end

puts

# ans = 0

# nums.each do |bunbo_10, bunshi_2, bunshi_5|
#   memo_inc_2.each_with_index do |row, index|
#     # 自身の bunbo_10 と相手の bunbo_10 を足した分だけ 2 * 5 を作る必要がある
#     requirement = bunbo_10 + index - 4
#     requirement = 0 if requirement < 0
#     # bunshi_5 が requirement 以上であれば、bunshi_2 が requirement 以上の数を足す
#     if bunshi_5 >= requirement
#       ans += row[requirement]
#     end
#   end

#   memo_inc_5.each_with_index do |row, index|
#     requirement = bunbo_10 + index - 4
#     requirement = 0 if requirement < 0
#     if bunshi_2 >= requirement
#       ans += row[requirement]
#     end
#   end

#   ans += memo_inc_0[4 - bunbo_10] if 4 - bunbo_10 >= 0

#   # 自身の bunbo_10 が 0 以下の場合、自身との組み合わせもカウントしているので -1
#   ans -= 1 if bunbo_10 <= 0
# end

# puts ans / 2