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);
        long[] cnt = new long[(int)1e5+1];
        long[] cnt2 = new long[(int)1e5+1];
        ArrayList<Integer> arr = new ArrayList<>();
        int n = sc.nextInt();
        long cl = 0;
        for(int i = 0; i < n; i++){
            String[] s = sc.next().split("\\.");
            if(s.length == 1){
                int k = Integer.parseInt(s[0]);
                cnt[k]++;
                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){
                    int k = Integer.parseInt(s[0]);
                    cnt[k]++;
                    cl++;
                }else if(last >= 5){
                    continue;
                }else{
                    int k = (int)rep2(10,4-last)*Integer.parseInt(s[1].substring(0,last));
                    //pw.println(k);
                    arr.add(k);
                    cnt2[k]++;
                }
            }
        }
        long ans = cl*(cl-1)/2L;
        //pw.println(ans);
        for(int a : arr){
            for(int i = 1; i <= 10000; i++){
                if((a*i) % 10000 == 0){
                    ans += cnt[i];
                }
            }
            for(int i = a; i <= 10000; i++){
                if((a*i) % 10000000 == 0){
                    if(a == i){
                        ans += cnt2[i]-1;
                    }
                    ans += cnt2[i];
                }
            }
        }
        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;
    } 
}