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 (Python):
class BIT:
    def __init__(self, n):
        
        self.BIT = [0] * (n + 1)
        self.n = n

    
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    
    def add(self, idx, x):
        while idx <= self.n:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return
def get_int(f):
    if "." not in f:
        return int(f),0
    return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(input())
p = [0] * n
for i in range(n):
    a, b = get_int(input())
    c, d = 0, 0
    while a % 2 == 0:
        c += 1
        a //= 2
    while a % 5 == 0:
        d += 1
        a //= 5
    c -= b
    d -= b
    p[i] = (c, d)
p.sort()

now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
    for j in range(now, i, -1):
        if p[i][0] + p[j][0] >= 0:
            t.add(-p[j][1] + 25, 1)
            now -= 1
        else:
            break
    if now < i:
        t.add(-p[i][1] + 25, -1)
    ans += max(0, t.query(25 + p[i][1]))

print(ans)

Solution (Python):
class BIT:
    def __init__(self, n):
        
        self.BIT = [0] * (n + 1)
        self.n = n

    
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    
    def add(self, idx, x):
        while idx <= self.n:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return
def get_int(f):
    if "." not in f:
        return int(f),0
    return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(input())
p = []
for i in range(n):
    a, b = get_int(input())
    c, d = 0, 0
    while a % 2 == 0:
        c += 1
        a //= 2
    while a % 5 == 0:
        d += 1
        a //= 5
    c -= b
    d -= b
    p.append((c, d))
p.sort(key=lambda x:x[0])
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
    for j in range(now, i, -1):
        if p[i][0] + p[j][0] >= 0:
            t.add(-p[j][1] + 25, 1)
            now -= 1
        else:
            break
    if now < i:
        t.add(-p[i][1] + 25, -1)
    ans += max(0, t.query(25 + p[i][1]))

print(ans)

Solution (Python):
class BIT:
    def __init__(self, n):
        
        self.BIT = [0] * (n + 1)
        self.n = n

    
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    
    def add(self, idx, x):
        while idx <= self.n:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return
def get_int(f):
    if "." not in f:
        return int(f),0
    return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(input())
p = []
for i in range(n):
    a, b = get_int(input())
    c, d = 0, 0
    while a % 2 == 0:
        c += 1
        a //= 2
    while a % 5 == 0:
        d += 1
        a //= 5
    c -= b
    d -= b
    p.append((c, d))
p.sort()
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
    for j in range(now, i, -1):
        if p[i][0] + p[j][0] >= 0:
            t.add(-p[j][1] + 25, 1)
            now -= 1
        else:
            break
    if now < i:
        t.add(-p[i][1] + 25, -1)
    ans += max(0, t.query(25 + p[i][1]))

print(ans)

Solution (Python):
import collections
import sys
input = sys.stdin.readline
N = int(input())
A = [input() for i in range(N)]

C = collections.defaultdict(int)
for i, x in enumerate(A):
    idx = 0
    x = x[:-1]
    if '.' in x:
        idx = x[::-1].index('.')
        x = x.replace('.', '')
    x = int(x)
    count2 = -idx
    count5 = -idx
    while(x % 2 == 0):
        x = x // 2
        count2 += 1

    while(x % 5 == 0):
        x = x // 5
        count5 += 1
    C[(count2, count5)] += 1
ans = 0
for a, b in C:
    for a2, b2 in C:
        if a+a2 >= 0 and b+b2 >= 0:
            if a == a2 and b == b2:
                ans += C[(a, b)]*(C[(a, b)]-1)
            else:
                ans += C[(a, b)]*C[(a2, b2)]
print(ans//2)

Solution (Python):

def s2int(a):
    dot_idx = -1
    for j in range(len(a)):
        if a[j] == '.':
            dot_idx = j
            break
    
    if dot_idx == -1:
        a += ".000000000"
    
    else:
        while len(a) < 10+dot_idx:
            a += "0"
    tmps = ""
    for j in range(len(a)):
        if a[j] == '.':continue
        tmps += a[j]
    return int(tmps)

def Count_two_five(x):
    c2 = 0
    c5 = 0
    while x > 0 and x % 2 == 0:
        x //= 2
        c2 += 1
    while x > 0 and x % 5 == 0:
        x //= 5
        c5 += 1
    c2 = min(c2, 18)
    c5 = min(c5, 18)
    return c2, c5

def main():
    N = int(input())

    C2 = [0] * N
    C5 = [0] * N

    for i in range(N):
        C2[i], C5[i] = Count_two_five(s2int(str(input())))

    Cc = [[0] * 19 for _ in range(19)]

    for i in range(N):
        Cc[C2[i]][C5[i]] += 1

    ans = 0
    for i in range(N):
        Cc[C2[i]][C5[i]] -= 1

        for j in range(19):
            for k in range(19):
                if C2[i] + j >= 18 and C5[i] + k >= 18:
                    ans += Cc[j][k]

        Cc[C2[i]][C5[i]] += 1

    print(ans//2)

main()

Solution (Python):

def s2int(a):
    dot_idx = -1
    for j in range(len(a)):
        if a[j] == '.':
            dot_idx = j
            break
    
    if dot_idx == -1:
        a += ".000000000"
    
    else:
        while len(a) < 10+dot_idx:
            a += "0"
    tmps = ""
    for j in range(len(a)):
        if a[j] == '.':continue
        tmps += a[j]
    return int(tmps)

def Count_two_five(x):
    c2 = 0
    c5 = 0
    while x > 0 and x % 2 == 0:
        x //= 2
        c2 += 1
    while x > 0 and x % 5 == 0:
        x //= 5
        c5 += 1
    c2 = min(c2, 18)
    c5 = min(c5, 18)
    return c2, c5

def main():
    N = int(input())

    C2 = [0] * N
    C5 = [0] * N

    for i in range(N):
        C2[i], C5[i] = Count_two_five(s2int(str(input())))

    Cc = [[0] * 19 for _ in range(19)]

    for i in range(N):
        Cc[C2[i]][C5[i]] += 1

    ans = 0
    for i in range(N):
        Cc[C2[i]][C5[i]] -= 1
        l2 = max(0, 18 - C2[i])
        l5 = max(0, 18 - C5[i])
        for j in range(l2, 19):
            for k in range(l5, 19):
                ans += Cc[j][k]
        Cc[C2[i]][C5[i]] += 1

    print(ans//2)

main()

Solution (Python):

def s2int(a):
    dot_idx = -1
    for j in range(len(a)):
        if a[j] == '.':
            dot_idx = j
            break
    
    if dot_idx == -1:
        a += ".000000000"
    
    else:
        while len(a) < 10+dot_idx:
            a += "0"
    tmps = ""
    for j in range(len(a)):
        if a[j] == '.':continue
        tmps += a[j]
    return int(tmps)

def Count_two_five(x):
    c2 = 0
    c5 = 0
    while x > 0 and x % 2 == 0:
        x //= 2
        c2 += 1
    while x > 0 and x % 5 == 0:
        x //= 5
        c5 += 1
    c2 = min(c2, 18)
    c5 = min(c5, 18)
    return c2, c5

N = int(input())

C2 = [0] * N
C5 = [0] * N

for i in range(N):
    C2[i], C5[i] = Count_two_five(s2int(str(input())))

Cc = [[0] * 19 for _ in range(19)]

for i in range(N):
    Cc[C2[i]][C5[i]] += 1

ans = 0
for i in range(N):
    Cc[C2[i]][C5[i]] -= 1
    l2 = max(0, 18 - C2[i])
    l5 = max(0, 18 - C5[i])
    for j in range(l2, 19):
        for k in range(l5, 19):
            ans += Cc[j][k]
    Cc[C2[i]][C5[i]] += 1

print(ans//2)

Solution (Python):
N = int(input())

C2 = [0] * N
C5 = [0] * N

for i in range(N):
    a = str(input())
    dot_idx = -1
    for j in range(len(a)):
        if a[j] == '.':
            dot_idx = j
            break
    
    if dot_idx == -1:
        a += ".000000000"
    
    else:
        while len(a) < 10+dot_idx:
            a += "0"
    tmps = ""
    for j in range(len(a)):
        if a[j] == '.':continue
        tmps += a[j]
    
    b = int(tmps)

    
    tmp = b
    while tmp > 0 and tmp % 2 == 0:
        tmp //= 2
        C2[i] += 1
    while tmp > 0 and tmp % 5 == 0:
        tmp //= 5
        C5[i] += 1
    C2[i] = min(C2[i], 18)
    C5[i] = min(C5[i], 18)

Cc = [[0] * 19 for _ in range(19)]

for i in range(N):
    Cc[C2[i]][C5[i]] += 1

ans = 0
for i in range(N):
    Cc[C2[i]][C5[i]] -= 1
    l2 = max(0, 18 - C2[i])
    l5 = max(0, 18 - C5[i])
    for j in range(l2, 19):
        for k in range(l5, 19):
            ans += Cc[j][k]
    Cc[C2[i]][C5[i]] += 1

print(ans//2)

Solution (Python):













import sys,collections
from math import floor
from decimal import Decimal
N = int(sys.stdin.readline())
a = tuple(sys.stdin.readline().rstrip() for _ in range(N)) 
a = [int(Decimal(e)*1000000000) for e in a]

d = collections.defaultdict(int)
for e in a:
    b = e
    t = 0
    while b != 0 and b % 2 == 0:
        t += 1
        b = b//2
    b = e
    f = 0
    while b != 0 and b % 5 == 0:
        f += 1
        b = b//5
    d[(min(f,18),min(t,18))] += 1

ret = 0
for ft1,v1 in d.items():
    for ft2,v2 in d.items():
        f1,t1 = ft1
        f2,t2 = ft2
        if ft1 < ft2:
            continue
        if f1+f2 >= 18 and t1+t2 >= 18:
            if ft1 == ft2:
                ret += (v1*(v2-1))//2
            else:
                ret += v1*v2
print(ret)

Solution (Python):
N=int(input())
A=[]
for i in range(N):
  tmp=float(input())*10**9
  if tmp%1>0.9:
    tmp+=0.1
  A.append(int(tmp))



dat=[[0]*19 for _ in range(19)]  
rui=[[0]*19 for _ in range(19)]

B=[]

for i in range(N):
  dev2,dev5=0,0
  while A[i]%2==0 and dev2<18:
    dev2+=1
    A[i]//=2
  while A[i]%5==0 and dev5<18:
    dev5+=1
    A[i]//=5
  dat[dev2][dev5]+=1
  B.append([dev2,dev5])
  
for i in range(19):
  for j in range(19):
    for k in range(i+1):
      for l in range(j+1):
        rui[k][l]+=dat[i][j]
  
ans=0
for i in range(N):
  dev2,dev5=B[i]
  t_dev2,t_dev5=18-dev2,18-dev5
  if dev2>=t_dev2 and dev5>=t_dev5:
    ans-=1
  ans+=rui[t_dev2][t_dev5]

print(ans//2)

Solution (Python):
N = int(input())

C2 = [0] * N
C5 = [0] * N

for i in range(N):
    a = str(input())
    dot_idx = -1
    for j in range(len(a)):
        if a[j] == '.':
            dot_idx = j
            break
    
    if dot_idx == -1:
        a += ".000000000"
    
    else:
        while len(a) < 10+dot_idx:
            a += "0"
    tmps = ""
    for j in range(len(a)):
        if a[j] == '.':continue
        tmps += a[j]
    
    b = int(tmps)

    
    tmp = b
    while tmp > 0 and tmp % 2 == 0:
        tmp //= 2
        C2[i] += 1
    while tmp > 0 and tmp % 5 == 0:
        tmp //= 5
        C5[i] += 1

Cc = [[0] * 19 for _ in range(19)]

for i in range(N):
    Cc[min(18, C2[i])][min(18, C5[i])]+=1

ans = 0
for i in range(N):
    if C2[i] >= 9 and C5[i] >= 9:
        ans -= 1
    l2 = max(0, 18 - C2[i])
    l5 = max(0, 18 - C5[i])
    for j in range(l2, 19):
        for k in range(l5, 19):
            ans += Cc[j][k]

print(ans//2)

Solution (Python):
N = int(input())
A = []
B = []
C2 = [0] * N
C5 = [0] * N


for i in range(N):
    a = str(input())
    ok = False
    dot_idx = -1
    l = len(a)
    for j in range(l):
        if a[j] == '.':
            ok = True
            dot_idx = j
    if dot_idx == -1:
        a += ".000000000"
    else:
        while len(a) < 10+dot_idx:
            a += "0"
    tmp = ""
    for j in range(len(a)):
        if a[j] == '.':continue
        tmp += a[j]

    B.append(int(tmp))
    tmp = B[i]
    tmp2 = B[i]
    while tmp > 0:
        if tmp % 2 == 0:
            tmp //= 2
            C2[i] += 1
        else:
            break
    while tmp2 > 0:
        if tmp % 5 == 0:
            tmp //= 5
            C5[i] += 1
        else:
            break


Cc = [[0] * 19 for _ in range(19)]

for i in range(N):
    Cc[min(18, C2[i])][min(18, C5[i])]+=1

ans = 0
for i in range(N):
    if C2[i] >= 9 and C5[i] >= 9:
        ans -= 1
    l2 = max(0, 18 - C2[i])
    l5 = max(0, 18 - C5[i])
    for j in range(l2, 19):
        for k in range(l5, 19):
            ans += Cc[j][k]
print(ans//2)

Solution (Python):

import sys
input = sys.stdin.readline
from decimal import Decimal
from math import gcd
from collections import Counter
n=int(input())
a=[int(Decimal(input())*10**9) for _ in range(n)]

tf = []

for i in range(n):
    t=0;f=0;
    while a[i]%2==0:
        t+=1
        a[i]//=2
    while a[i]%5==0:
        f+=1
        a[i]//=5
    tf.append((t-9,f-9))

ctf = Counter(tf)
ans=0
for t,f in ctf:
    for t2,f2 in ctf:
        if t+t2>=0 and f+f2>=0:
            if t!=t2 or f!=f2:
                ans+= ctf[(t,f)]*ctf[(t2,f2)]
            else:
                ans+= ctf[(t,f)]*(ctf[(t,f)]-1)
print(ans//2)

Solution (Python):
N=int(input())
A=[]
for i in range(N):
  
  inp=input()
  ten=inp.find(".")
  L=len(inp)
  batu=9
  if ten!=-1:
    batu-=L-ten-1
  inp=inp.replace(".","")
  inp=int(inp)
  inp*=10**batu
  A.append(inp)



dat=[[0]*19 for _ in range(19)]  
rui=[[0]*19 for _ in range(19)]

B=[]

for i in range(N):
  dev2,dev5=0,0
  while A[i]%2==0 and dev2<18:
    dev2+=1
    A[i]//=2
  while A[i]%5==0 and dev5<18:
    dev5+=1
    A[i]//=5
  dat[dev2][dev5]+=1
  B.append([dev2,dev5])
  
for i in range(19):
  for j in range(19):
    for k in range(i+1):
      for l in range(j+1):
        rui[k][l]+=dat[i][j]
  
ans=0
for i in range(N):
  dev2,dev5=B[i]
  t_dev2,t_dev5=18-dev2,18-dev5
  if dev2>=t_dev2 and dev5>=t_dev5:
    ans-=1
  ans+=rui[t_dev2][t_dev5]

print(ans//2)

Solution (Python):
from numpy import*
def main():
  c=zeros((50,50),int_)
  r=0
  for a in[*open(0)][1:]:
    a=round(float(a)*1e9)
    y=0
    while a%5<1:
      a//=5
      y+=1
    x=int(log2(a&-a))
    r+=sum(c[max(0,18-x):,max(0,18-y):])
    c[x][y]+=1
  print(r)
main()

Solution (Python):
c=eval('[0]*50,'*50)
r=0
for a in[*open(0)][1:]:
 a=round(float(a)*1e9);y=1
 while a%5**y<1:y+=1
 x=len(bin(a&-a));r+=sum(sum(d[max(0,20-y):])for d in c[max(0,24-x):]);c[x][y]+=1
print(r)

Solution (Python):
c=eval('[0]*50,'*50)
r=0
for a in[*open(0)][1:]:
 a=round(float(a)*1e9);x=y=1
 while a%2**x<1:x+=1
 while a%5**y<1:y+=1
 r+=sum(sum(d[max(0,20-y):])for d in c[max(0,20-x):]);c[x][y]+=1
print(r)

Solution (Python):
def conv(s):
    if s.find('.') == -1:
        s += '.'
    s = s.rstrip('0')
    t = len(s) - s.find('.') - 1
    a = int(s.replace('.', ''))
    if a == 0:
        return (0, 0)
    x, y = -t, -t
    while a % 5 == 0:
        x += 1
        a //= 5
    while a % 2 == 0:
        y += 1
        a //= 2
    return (x, y)


N, *A = open(0).read().split()
N = int(N)

d = {}
for a in A:
    t = conv(a)
    d.setdefault(t, 0)
    d[t] += 1

result = 0
xs = list(d.keys())
for i in range(len(xs)):
    x, y = xs[i]
    t = d[xs[i]]
    if x >= 0 and y >= 0:
        result += t * (t - 1) // 2
    for j in range(i + 1, len(xs)):
        m, n = xs[j]
        if x + m >= 0 and y + n >= 0:
            result += t * d[xs[j]]
print(result)

Solution (Python):
from collections import defaultdict

n = int(input())
d = defaultdict()

for _ in range(n):
    a = input()
    if '.' in a:
        b = a.split('.')
        a = int(b[0] + b[1])
        cnt2 = -len(b[1])
        cnt5 = -len(b[1])
    else:
        a = int(a)
        cnt2 = 0
        cnt5 = 0
    while a % 2 == 0:
        cnt2 += 1
        a //= 2
    while a % 5 == 0:
        cnt5 += 1
        a //= 5
    if (cnt2, cnt5) in d:
        d[(cnt2, cnt5)] += 1
    else:
        d[(cnt2, cnt5)] = 1

ans = 0

for k1, v1 in d.items():
    for k2, v2 in d.items():
        x1, y1 = k1
        x2, y2 = k2
        if k1 != k2:
            if x1 + x2 >= 0 and y1 + y2 >= 0:
                ans += v1 * v2
        else:
            if x1 + x2 >= 0 and y1 + y2 >= 0:
                ans += v1 * (v1 - 1)

print(ans // 2)

Solution (Python):
def conv(s):
    if s.find('.') == -1:
        s += '.'
    s = s.rstrip('0')
    t = len(s) - s.find('.') - 1
    a = int(s.replace('.', ''))
    if a == 0:
        return (0, 0)
    x, y = -t, -t
    while a % 5 == 0:
        x += 1
        a //= 5
    while a % 2 == 0:
        y += 1
        a //= 2
    return (x, y)


N, *A = open(0).read().split()
N = int(N)

d = {}
for a in A:
    t = conv(a)
    d.setdefault(t, 0)
    d[t] += 1

result = 0
xs = list(d.keys())
for i in range(len(xs)):
    x, y = xs[i]
    t = d[xs[i]]
    if x >= 0 and y >= 0:
        result += t * (t - 1) // 2
    for j in range(i + 1, len(xs)):
        m, n = xs[j]
        if x + m >= 0 and y + n >= 0:
            result += t * d[xs[j]]
print(result)

Solution (Python):
c=eval('[0]*50,'*50)
r=0
for a in[*open(0)][1:]:
 a=round(float(a)*1e9);x=y=0
 while a%2<1:a//=2;x+=1
 while a%5<1:a//=5;y+=1
 r+=sum(sum(d[max(0,18-y):])for d in c[max(0,18-x):]);c[x][y]+=1
print(r)

Solution (Python):
import collections

def calc(n):
  cnt_2=0
  cnt_5=0
  while n%2==0 and cnt_2<18:
    cnt_2+=1
    n//=2
  while n%5==0 and cnt_5<18:
    cnt_5+=1
    n//=5
  return [cnt_2,cnt_5]

n=int(input())
dic=collections.defaultdict(int)
ans=0
for _ in range(n):
  tmp=input()
  if '.' in tmp:
    pos=tmp.index('.')
    d=len(tmp)-(pos+1)
    tmp=tmp[:pos]+tmp[pos+1:]+'0'*(9-d)
  else:
    tmp+='0'*9
  tmp=int(tmp)
  cnt_2,cnt_5=calc(tmp)
  dic[(cnt_2,cnt_5)]+=1
  if 18<=min(cnt_2*2,cnt_5*2):
    ans-=1
for a1,b1 in dic.keys():
  for a2,b2 in dic.keys():
    if min(a1+a2,b1+b2)>=18:
      ans+=dic[(a1,b1)]*dic[(a2,b2)]
print(ans//2)

Solution (Python):
import collections

def calc(n):
  cnt_2=0
  cnt_5=0
  while n%2==0 and cnt_2<18:
    cnt_2+=1
    n//=2
  while n%5==0 and cnt_5<18:
    cnt_5+=1
    n//=5
  return [cnt_2,cnt_5]

n=int(input())
dic=collections.defaultdict(int)
ans=0
for _ in range(n):
  tmp=input()
  if '.' in tmp:
    pos=tmp.index('.')
    d=len(tmp)-(pos+1)
    tmp=tmp[:pos]+tmp[pos+1:]+'0'*(9-d)
  else:
    tmp+='0'*9
  tmp=int(tmp)
  cnt_2,cnt_5=calc(tmp)
  dic[(cnt_2,cnt_5)]+=1
  if 18<=min(cnt_2*2,cnt_5*2):
    ans-=1
for a1,b1 in dic.keys():
  for a2,b2 in dic.keys():
    if min(a1+a2,b1+b2)>=18:
      ans+=dic[(a1,b1)]*dic[(a2,b2)]
print(ans//2)

Solution (Python):
c=eval('[0]*50,'*50)
r=0
for a in[*open(0)][1:]:
 a=round(float(a)*10**9);x=y=0
 while a%2<1:a//=2;x+=1
 while a%5<1:a//=5;y+=1
 r+=sum(sum(d[max(0,18-y):])for d in c[max(0,18-x):]);c[x][y]+=1
print(r)

Solution (Python):
c=[[0]*50for _ in range(50)]
r=0
for a in[*open(0)][1:]:
  a=round(float(a)*10**9)
  x=y=0
  while a%2<1:
    a//=2
    x+=1
  while a%5<1:
    a//=5
    y+=1
  r+=sum(sum(d[max(0,18-y):])for d in c[max(0,18-x):])
  c[x][y]+=1
print(r)

Solution (Python):
'''
自宅用PCでの解答
'''
import math

import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    s25 = [[0]*19 for i in range(19)] 
    nms = [] 
    n = int(ipt())
    for _ in range(n):
        a = float(ipt())*(10**9)+0.1
        ia = int(a)
        for i in range(19):
            if ia%2 != 0:
                t2 = i
                break
            elif i == 18:
                t2 = 18
            else:
                ia //= 2
        for i in range(19):
            if ia%5 != 0:
                t5 = i
                break
            elif i == 18:
                t5 = 18
            else:
                ia //= 5
        s25[18-t2][18-t5] += 1
        nms.append((t2,t5))

    ss = s25
    for i in range(1,19):
        ss[0][i] += ss[0][i-1]
        ss[i][0] += ss[i-1][0]
    for i in range(1,19):
        for j in range(1,19):
            ss[i][j] += ss[i-1][j]+ss[i][j-1]-ss[i-1][j-1]


    ans = 0
    for t2,t5 in nms:
        ans += ss[t2][t5]
        if t2 >= 9 and t5 >= 9:
            ans -= 1

    print(ans//2)

    return None

if __name__ == '__main__':
    main()

Solution (Python):
from decimal import Decimal
n = int(input())
a = []
r = {}
for i in range(n):
    d = int(float(input())*10**9+0.01)
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in r.keys():
    for i , j in r.keys():
        if min(x+i,y+j) >= 18:
            ans += r[(x,y)]*r[(i,j)]
            if x == i and y == j:
                ans -= r[(x,y)]
                
print(ans//2)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from collections import defaultdict
dic = defaultdict(int)
for _ in range(N):
    a = float(input())*(10**9)
    a = int(a+0.1)
    num2, num5 = 0, 0
    while a%2==0:
        a//=2
        num2+=1
        if num2>18: break
    while a%5==0:
        a//=5
        num5+=1
        if num5>18: break
    dic[(num2, num5)] += 1

keys = list(dic.keys())
length = len(keys)
ans = 0
for i in range(length):
    a2, a5 = keys[i]
    a_cnt = dic[(a2, a5)]
    for j in range(i, length):
        b2, b5 = keys[j]
        b_cnt = dic[(b2, b5)]
        if a2+b2>=18 and a5+b5>=18:
            if i==j:
                ans += (a_cnt)*(b_cnt-1)//2
            else:
                ans += a_cnt*b_cnt
print(ans)

Solution (Python):
from decimal import Decimal
n = int(input())
a = []
r = {}
for i in range(n):
    d = int(float(input())*10**9 + 0.1)
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[(d2,d5)] = r.get((d2,d5),0) + 1
ans = 0
for x , y in r.keys():
    for i , j in r.keys():
        if min(x+i,y+j) >= 18:
            ans += r[(x,y)]*r[(i,j)]
            if x == i and y == j:
                ans -= r[(x,y)]
                
print(ans//2)

Solution (Python):
import collections

def calc(n):
  cnt_2=0
  cnt_5=0
  while n%2==0:
    cnt_2+=1
    n//=2
  while n%5==0:
    cnt_5+=1
    n//=5
  if cnt_2>18:
    cnt_2=18
  if cnt_5>18:
    cnt_5=18
  return [cnt_2,cnt_5]

n=int(input())
dic=collections.defaultdict(int)
ans=0
for _ in range(n):
  tmp=input()
  if '.' in tmp:
    pos=tmp.index('.')
    d=len(tmp)-(pos+1)
    tmp=tmp[:pos]+tmp[pos+1:]
  else:
    d=0
  tmp=int(tmp)
  cnt_2,cnt_5=calc(tmp)
  dic[(cnt_2,cnt_5,d)]+=1
  if 2*d<=min(cnt_2*2,cnt_5*2):
    ans-=1
for a1,b1,d1 in dic.keys():
  for a2,b2,d2 in dic.keys():
    if min(a1+a2,b1+b2)>=d1+d2:
      ans+=dic[(a1,b1,d1)]*dic[(a2,b2,d2)]
print(ans//2)

Solution (Python):

N = int(input())

bucket = dict()

def keyGen(num,den=1):
	c2 = 0
	c5 = 0
	while num%2==0:
		c2+=1
		num/=2
	while den%2==0:
		c2-=1
		den/=2
	while num%5==0:
		c5+=1
		num/=5
	while den%5==0:
		c5-=1
		den/=5
	return (c2,c5)

def addItem(d,key1):
	if key1 in d:
		d[key1]+=1
	else:
		d[key1]=1

for _ in range(N):
	theNumber = input()
	dpoint = theNumber.find('.')
	if(dpoint>-1):
		a=int(theNumber[:dpoint])
		lenOfDen = len(theNumber[1+dpoint:])
		b=int(theNumber[1+dpoint:])
		num = a*10**lenOfDen+b
		den = 10**lenOfDen
		addItem(bucket,keyGen(num,den))
	else:
		addItem(bucket,keyGen(int(theNumber)))

s=0
for it in bucket:
	x1 = it[0]
	y1 = it[1]
	r1 = bucket[it]
	for it2 in bucket:
		x2 = it2[0]
		y2 = it2[1]
		r2 = bucket[it2]
		if x1+x2>=0 and y1+y2>=0:
			if(it<it2):
				s+=r1*r2
			elif(it==it2):
				s+=(r1*(r1-1))//2

print(s)

Solution (Python):
N=int(input())
A=[input() for i in range(N)]
d=[[0]*50 for i in range(50)]
div=[]
for a in A:
    if '.' in a:
        i=a.index('.')
        n=int(a[:i])*10**9+int(a[i+1:]+'0'*(10-len(a)+i))
    else:
        n=int(a)*10**9
    t,f=0,0
    while n%2==0:
        n//=2
        t+=1
    while n%5==0:
        n//=5
        f+=1
    d[t+1][f+1]+=1
    div.append((t,f))
for i in range(49):
    for j in range(49):
        d[i+1][j+1]+=d[i+1][j]+d[i][j+1]-d[i][j]
r=0
for t,f in div:
    r+=d[-1][-1]-d[-1][max(0,18-f)]-d[max(0,18-t)][-1]+d[max(0,18-t)][max(0,18-f)]
    if max(0,18-t)<=t and max(0,18-f)<=f:
        r-=1
print(r//2)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)
import math





from decimal import Decimal

INF = 1 << 50



def run():
    N = int(sysread())
    A = [Decimal(input()) for _ in range(N)]
    M = [[0] * 19 for _ in range(19)]
    
    minus = 0
    
    MULT = 10 ** 9
    for i, a in enumerate(A):
        if a == int(a):
            minus += 1
        a *= MULT
        a = int(a)
        
        
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (min(f2, 18), min(f5, 18))
        M[min(f2, 18)][min(f5, 18)] += 1

        
    
    
    
    
    for i in range(18, -1, -1):
        for j in range(18, -1, -1):
            if i > 0:
                M[i-1][j] += M[i][j]
                
    for i in range(18, -1, -1):
        for j in range(18, -1, -1):
            if j > 0:
                M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    
    
    

if __name__ == "__main__":
    run()

Solution (Python):
import decimal
n = int(input())

cum = [[0]*50 for i in range(50)]

l = []
for i in range(n):
    x = decimal.Decimal(input())
    x *= 10**9
    x = int(x)
    
    two = 0
    while x%2 == 0:
        x //= 2
        two += 1
    five = 0
    while x%5 == 0:
        x //= 5
        five += 1
    cum[two][five] += 1
    l.append((two,five))

for i in range(48,-1,-1):
    for j in range(48,-1,-1):
        cum[i][j] += cum[i][j+1]+cum[i+1][j]-cum[i+1][j+1]

ans = 0
for i,j in l:
    x = max(18-i,0)
    y = max(18-j,0)
    if x <= i and y <= j:
        ans += cum[x][y]-1
    else:
        ans += cum[x][y]
print(ans//2)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
from decimal import *
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.readline())
def FI(): return float(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
D = defaultdict(lambda:defaultdict(int))
for j in range(n):
    a = input()
    r = len(a) - a.find(".") - 1 if "." in a else 0
    a = a.replace(".", "")
    cnt1 = -r
    cnt2 = -r
    a = int(a)
    while a % 2 == 0:
        a //= 2
        cnt1 += 1
    while a % 5 == 0:
        a //= 5
        cnt2 += 1
    D[cnt1][cnt2] += 1

ans = 0
for i in range(-20, 30):
    for k in range(-10, 15):
        for j in range(-20, 30):
            for l in range(-10, 15):
                if i + j >= 0 and k + l >= 0:
                    if i == j and k == l:
                        ans += D[i][k] * (D[j][l] - 1)
                    else:
                        ans += D[i][k] * D[j][l]

print(ans // 2)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
from decimal import *
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce
from operator import mul
from pprint import pprint



sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.readline())
def FI(): return float(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
D = defaultdict(lambda:defaultdict(int))
for j in range(n):
    a = input()
    r = len(a) - a.find(".") - 1 if "." in a else 0
    a = a.replace(".", "")
    a = int(a) * 10 ** (9 - r)
    cnt1 = 0
    cnt2 = 0
    while a % 2 == 0:
        a //= 2
        cnt1 += 1
    while a % 5 == 0:
        a //= 5
        cnt2 += 1
    D[cnt1][cnt2] += 1

ans = 0
for i in range(50):
    for j in range(25):
        for k in range(50):
            for l in range(25):
                if min(i + k, j + l) >= 18:
                    if i == k and j == l:
                        ans += D[i][j] * (D[k][l] - 1)
                    else:
                        ans += D[i][j] * D[k][l]


print(ans // 2)

Solution (Python):
def solve():
    from collections import defaultdict
    from fractions import Fraction
    n = int(input())
    d = defaultdict(int)
    for i in range(n):
        x = Fraction(input())
        x *= 10 ** 9
        cnt2, cnt5 = 0, 0
        while x % 5 == 0:
            x //= 5
            cnt5 += 1
        while x % 2 == 0:
            x //= 2
            cnt2 += 1
        d[(cnt2, cnt5)] += 1
    lis = list(d)
    ans_0 = 0
    ans_f = 0
    for a, b in lis:
        k = d[(a, b)]
        for x, y in lis:
            l = d[(x, y)]
            if a >= 9 and b >= 9 and (a, b) == (x, y):
                ans_0 += k * (k - 1)
            elif a + x >= 18 and b + y >= 18:
                ans_f += k * l
    print((ans_0 + ans_f) // 2)
    return


solve()