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: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
int dp[4][35][35];
struct inf{
	int ty;
	int v1,v2;
};
inf arr[222222];
int main(void){
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		string a;
		cin >> a;
		lld ll = 0,rr = 0,sz = 1,ty = 0;
		for(int e=0;e<sz(a);e++){
			if(a[e]=='.'){
				ty = 1;
				continue;
			}
			if(ty==0){
				ll = ll*10 + (a[e]-'0');
			}else{
				rr = rr*10 + (a[e]-'0');
				sz *= 10;
			}
		}
		ll *= sz;
		ll += rr;
		lld lm = __gcd(ll,sz);
		ll /= lm;
		sz /= lm;
		int f2 =0,f5 =0,s2 =0, s5=0;
		while(ll!=0){
			if(ll%2==0){
				f2++;
				ll/=2;
			}else if(ll%5==0){
				f5++;
				ll/=5;
			}else break;
		}
		while(sz!=0){
			if(sz%2==0){
				s2++;
				sz/=2;
			}else if(sz%5==0){
				s5++;
				sz/=5;
			}else break;
		}
		if(s2==0&&s5==0){
			dp[0][f2][f5]++;
		}else if(f2&&f5==0&&s2==0&&s5){
			dp[1][f2][s5]++;
		}else if(f2==0&&f5&&s2&&s5==0){
			dp[2][f5][s2]++;
		}else if(f2==0&&f5==0){
			dp[3][s2][s5]++;
		}
	}
	lld ans = 0;
	lld tot1 = 0;
	for(int e=0;e<33;e++){
		for(int p=0;p<33;p++){
			tot1 += dp[0][e][p];
		}
	}
	ans += (tot1*(tot1-1))/2;
	for(int e=0;e<33;e++){
		for(int p=0;p<33;p++){
			for(int q=0;q<=e;q++){
				for(int r=0;r<=e;r++){
					ans += (dp[0][e][p]*dp[3][q][r]);
				}
			}
		}
	}
	for(int e=0;e<33;e++){
		for(int p=0;p<33;p++){
			for(int q=0;q<33;q++){
				for(int r=0;r<=p;r++){
					ans += (dp[0][e][p]*dp[1][q][r]);
				}
			}
			for(int q=0;q<=e;q++){
				for(int r=0;r<33;r++){
					ans += (dp[0][e][p]*dp[2][r][q]);
				}
			}
		}
	}
	for(int e=0;e<33;e++){
		for(int p=0;p<33;p++){
			for(int q=p;q<33;q++){
				for(int r=0;r<=e;r++){
					ans += (dp[1][e][p]*dp[2][q][r]);
				}
			}
		}
	}
	printf("%lld",ans);
	return 0;
}