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

import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        HashMap<Long,Integer> map = new HashMap<>();
        int n = sc.nextInt();
        ArrayList<Long> arr = new ArrayList<>();
        long cl = 0;
        for(int i = 0; i < n; i++){
            String[] s = sc.next().split("\\.");
            if(s.length == 1){
                long k = Integer.parseInt(s[0])*10000;
                map.put(k,map.getOrDefault(k,0)+1);
                cl++;
            }else{
                int last = s[1].length();
                for(int j = s[1].length()-1; j >= 0; j--){
                    if(s[1].charAt(j) == '0'){
                        last = j;
                    }else{
                        break;
                    }
                }
                if(last == 0){
                    long k = Integer.parseInt(s[0])*10000;
                    map.put(k,map.getOrDefault(k,0)+1);
                    cl++;
                }else if(last >= 5){
                    continue;
                }else{
                    long k = Integer.parseInt(s[0])*10000 + (int)rep2(10,4-last)*Integer.parseInt(s[1].substring(0,last));
                    long k2 = k%10000;
                    map.put(k,map.getOrDefault(k,0)+1);
                    arr.add(k2);
                }
            }
        }
        long ans = cl*(cl-1)/2L;
        for(long a : arr){
            long now = 10000;
            boolean flg = false;
            for(int i = 0; i < 5; i++){
                if(now % a != 0){
                    now *= 10;
                }else{
                    flg = true;
                    now *= now / a;
                    int pow = i*2;
                    while(pow > 0){
                        now /= 10;
                        pow--;
                    }
                    break;
                }
            }
            if(!flg){
                now = 10000;
                for(int i = 0; i < 5; i++){
                    if(a % 10000 != 0){
                        a *= 10;
                        now *= 10;
                    }else{
                        break;
                    }
                }
            }
            for(long i = 1; i <= 1000; i++){
                ans += map.getOrDefault(now*i,0);
            }
        }
        pw.println(ans);
        pw.flush();
    }
    
    private static long rep2(long b, long n){
        if(n == 0) return 1;
        if(n == 1) return b;
        long bn = rep2(b,n/2);
        if(n % 2 == 0){
            return bn*bn;
        }else{
            return bn*bn*b;
        }
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}