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>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define IN freopen("alchemy_input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)

#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define xx first
#define yy second
#define ln 17
#define off 2

#define sq(x) ((x)*(x))

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;

//#define log 20
#define mod 1000000007LL
#define INF 2000000000
#define maxn 200005

const long double eps = 1e-9 ;

i64 a[maxn] ;

int two[25][75] , five[25][75] ;
int cnt[25] ;

int main()
{
    int n ;

    scanf("%d",&n) ;

    for(int i=1 ; i<=n ; i++)
    {
        char s[55] ;
        scanf("%s",s) ;
        i64 num = 0 , cnt = 0 , fl = 0 ;
        for(int j=0 ; s[j]!='\0' ; j++)
        {
            if(s[j]=='.')
            {
                fl = 1 ;
                continue ;
            }
            cnt += fl ;
            num = num*10 + s[j]-'0' ;
        }
        for(int j=1 ; j<=9-cnt ; j++) num *= 10 ;
        a[i] = num ;
//        printf("%lld\n",a[i]) ;
    }

    i64 ans = 0 ;

    for(int i=1;  i<=n ; i++)
    {
        int p10 = 0 ;
        while( a[i]%10 == 0 )
        {
            p10++ ;
            a[i] /= 10 ;
        }
        int p2 = 0 , p5 = 0 ;
        while( a[i]%2 == 0 )
        {
            a[i] /= 2 ;
            p2++ ;
        }
        while( a[i]%5 == 0 )
        {
            a[i] /= 5 ;
            p5++ ;
        }
        for(int j=0 ; j<=15 ; j++)
        {
            if( p10+j >= 18 ) ans += cnt[j] ;
            else{

                if( p2 > 18-(p10+j) ) ans += five[j][ 18-(p10+j) ] ;
                if( p5 > 18-(p10+j) ) ans += two[j][ 18-(p10+j) ] ;
            }
        }
        cnt[p10]++ ;
        if( p2 > 0 )
        {
            for(int j=p2 ; j>=0 ; j--) two[p10][j]++ ;
        }
        if(p5>0)
        {
            for(int j=p5 ; j>=0 ; j--) five[p10][j]++ ;
        }
    }

    printf("%lld\n",ans) ;

    return 0 ;
}