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 C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <tuple>
using namespace std;

typedef long long ll;

int main () {
	int N;
	map <ll, ll> fit;
	map <ll, ll> bit;
	ll mat[20][20];
	for (int c=0; c<20; c++) {
		for (int r=0; r<20; r++) {
			mat[c][r] = 0;
		}
	}

	ll ans = 0;
	int zcnt = 0;
	cin >> N;
	for (int n=0; n<N; n++) {
		char s[20] = {0};
		cin >> s;
		int j = 0, k = 0;
		int i = 0;
		for (i=0; s[i]!='\0'; i++) {
			if (s[i]=='.') {
				j = i+1;
				s[i] = '\0';
			}
			k++;
		}
		k--;
		ll d = atol (s) * 1000000000;
		ll l = 0;
		ll b = 1, bbc = 0;
		if (j != 0) {
			while (s[k]=='0')
				k --;
			while ('0'<=s[k] && s[k]<='9') {
				l += (ll)(s[k]-'0')*b;
				b *= 10;
				bbc++;
				k --;
			}
		}
		ll sum = d + l*(1000000000/b);
		if (sum == 0)
			zcnt ++;
		// cout << sum << endl;
		int bl = 0, fl = 0;
		while (sum%2==0 && sum!=0) {
			bl ++;
			if (bl>9)
				bit[bl-9] ++;
			sum /= 2;
		}
		int bm = 0;
		if (bl<9)
			bm = bl;;
		while (sum%5==0 && sum!=0) {
			fl ++;
			if (fl>9)
				fit[fl-9] ++;
			sum /= 5;
		}
		int fm = 0;
		if (fl<9)
			fm = fl;
		if (sum!=0)
			mat[bl][fl] ++;
	}
	while (zcnt>0) {
		ans += N-zcnt;
		zcnt --;
	}
	/*
	for (int c=0; c<20; c++) {
		if (c==9) {
			for (int r=0; r<22; r++)
				cout << "--";
			cout << endl;
		}
		for (int r=0; r<20; r++) {
			if (r==9)
				cout << "| ";
			cout << mat[c][r] << " ";
		}
		cout << endl;
	}
	*/
	for (int c=0; c<9; c++) {
		for (int r=0; r<9; r++) {
			for (int cp=18-c; cp<20; cp++) {
				for (int rp=18-r; rp<20; rp++) {
					ans += mat[c][r] * mat[cp][rp];
				}
			}
		}
	}
	// cout << ans << endl;
	for (int c=0; c<9; c++) {
		for (int r=9; r<20; r++) {
			for (int cp=18-c; cp<20; cp++) {
				for (int rp=0; rp<20; rp++) {
					ans += mat[c][r] * mat[cp][rp];
				}
			}
		}
	}
	// cout << ans << endl;
	for (int c=9; c<20; c++) {
		for (int r=0; r<9; r++) {
			for (int cp=c+1; cp<20; cp++) {
				for (int rp=18-r; rp<20; rp++) {
					ans += mat[c][r] * mat[cp][rp];
				}
			}
		}
	}
	// cout << ans << endl;
	for (int c=9; c<20; c++) {
		for (int r=9; r<20; r++) {
			for (int cp=c; cp<20; cp++) {
				for (int rp=r; rp<20; rp++) {
					if (c==cp && r==rp)
						ans += mat[c][r] * (mat[c][r]-1) / 2;
					else
						ans += mat[c][r] * mat[cp][rp];
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}