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 Java (OpenJDK 11.0.6) (judge verdict: Wrong Answer)

import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.nextInt();
        int[][] A = new int[40][40]; // 20 is 0
        for (int n = 0; n < N; n++) {
            BigDecimal bd = in.nextBigDecimal();
            bd = bd.multiply(BigDecimal.valueOf(1000000000));
            long l = bd.longValue();
            int t = 20;
            int f = 20;
            for (long x = l * 15625 / 2; x % 1000000000 == 0; x /= 2)
                t++;
            for (long x = l * 15625; x % 1000000000 != 0; x *= 2)
                t--;
            for (long x = l * 16384 / 5; x % 1000000000 == 0; x /= 5)
                f++;
            for (long x = l * 16384; x % 1000000000 != 0; x *= 5)
                f--;
            if (t >= 0 && f >= 0)
                A[t][f]++;
        }
        int[][] B = new int[40][40];
        for (int i = 0; i < 40; i++) for (int j = 0; j < 40; j++)
            B[i][j] = A[i][j];
        for (int i = 0; i < 40; i++) for (int j = 39; j > 0; j--)
            B[i][j - 1] += B[i][j];
        for (int i = 0; i < 40; i++) for (int j = 39; j > 0; j--)
            B[j - 1][i] += B[j][i];

        long ans = 0;
        for (int i = 1; i < 40; i++) for (int j = 1; j < 40; j++) {
            if (i >= 20 && j >= 20)
                ans += A[i][j] * (B[40 - i][40 - j] - 1);
            else
                ans += A[i][j] * B[40 - i][40 - j];
        }
        out.println(ans / 2);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}