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



Sample input:
5
7.5
2.4
17.000000001
17
16.000000000


Sample output:
3

Submission status: Runtime Error

Solution code:
from decimal import Decimal

n = int(input())
a = [0] * n
for x in range(n):
    a[x] = Decimal(input())
flag = False
cnt = 0
for i, v in enumerate(a, start=1):
    if i == n:
        continue
    for j in range(i, n):
        ans = str(v * a[j])
        try:
            idx = ans.index(".")
        except ValueError:
            idx = len(ans)
        try:
            f = int(float(ans[idx + 1 :]))
        except ValueError:
            pass
        if f == 0:
            cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math
import bisect

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = [int(float(input())*10**9) for i in range(n)]
c = Counter([i%10**9 for i in a])
ans = 0

for i in c:
	if i!=0:
		for j in range(0,len(a)):
			if i*a[j]%10**18==0:
				ans+=1

c1 = math.factorial(c[0])//(math.factorial(2)*math.factorial(c[0]-2))

print(ans+c1)

Submission status: Runtime Error

Solution code:
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy

def process(num):
    cnt_2 = 0
    cnt_5 = 0

    while num%2 == 0:
        num = num//2
        cnt_2 += 1
    
    while num%5 == 0:
        num = num//5
        cnt_5 += 1
    
    return cnt_2-9, cnt_5-9


def solve(lst):  # fix inputs here
    console("----- solving ------")

    grid = [[0 for _ in range(20)] for _ in range(20)]

    console(lst)
    for num in lst:
        x,y = process(num)
        console(x,y)
        grid[x+10][y+10] += 1
    # return a string (i.e. not a list or matrix)

    # console(np.array(grid))

    res = 0

    for i in range(-9,9):
        for j in range(-9,9):
            smaller_cnt = 0
            # smaller_cnt -= grid[10+i][10+j]
            for x in range(10-i,20):
                for y in range(10-j,20):
                    smaller_cnt += grid[x][y]
            # val = grid[10+i][10+j] * smaller_cnt + (grid[10+i][10+j] * (grid[10+i][10+j] - 1))
            if i >= 0 and j >= 0:
                val = grid[10+i][10+j] * (smaller_cnt - grid[10+i][10+j]) 
                val += (grid[10+i][10+j] * (grid[10+i][10+j]-1))
            else:
                val = (grid[10+i][10+j]) * smaller_cnt
            if val != 0:
                console(i,j,smaller_cnt,val)
            val = max(0,val)
            res += val
    console(res)
    return res//2


def console(*args):  # the judge will not read these print statement
    # print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

# for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
nrows = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    # lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
grid = []
for _ in range(nrows):
    grid.append(int(10**9 * float(input())))

res = solve(grid)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(Decimal(input()))
count = 0
for i in range(n-1):
    for j in range(n-i-1):
        result = Decimal(a[i] * a[i + j + 1])
        if math.isclose(result % 1, 0.00000, abs_tol=1e-100):
            count += 1
        # if result.is_integer():
        #     count += 1

print(count)

Submission status: Runtime Error

Solution code:
import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
import numpy as np
# import scipy

def process(num):
    cnt_2 = 0
    cnt_5 = 0

    while num%2 == 0:
        num = num//2
        cnt_2 += 1
    
    while num%5 == 0:
        num = num//5
        cnt_5 += 1
    
    return cnt_2-9, cnt_5-9


def solve(lst):  # fix inputs here
    console("----- solving ------")

    grid = [[0 for _ in range(20)] for _ in range(20)]

    console(lst)
    for num in lst:
        x,y = process(num)
        console(x,y)
        grid[x+10][y+10] += 1
    # return a string (i.e. not a list or matrix)

    console(np.array(grid))

    res = 0

    for i in range(-9,9):
        for j in range(-9,9):
            smaller_cnt = 0
            # smaller_cnt -= grid[10+i][10+j]
            for x in range(10-i,20):
                for y in range(10-j,20):
                    smaller_cnt += grid[x][y]
            # val = grid[10+i][10+j] * smaller_cnt + (grid[10+i][10+j] * (grid[10+i][10+j] - 1))
            if i >= 0 and j >= 0:
                val = grid[10+i][10+j] * (smaller_cnt - grid[10+i][10+j]) 
                val += (grid[10+i][10+j] * (grid[10+i][10+j]-1))
            else:
                val = (grid[10+i][10+j]) * smaller_cnt
            if val != 0:
                console(i,j,smaller_cnt,val)
            val = max(0,val)
            res += val
    console(res)
    return res//2


def console(*args):  # the judge will not read these print statement
    # print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

# for case_num in [1]:
    # read line as a string
    # strr = input()

    # read line as an integer
nrows = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
    # lst = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
grid = []
for _ in range(nrows):
    grid.append(int(10**9 * float(input())))

res = solve(grid)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
print(res)

Submission status: Runtime Error

Solution code:
def power_mod(a,b):
  ans = 0
  while not a%b:
    a=a//b
    ans += 1
  return ans

#print(power_mod(12,2))

N = int(input())
A = [int(float(input())*(10**9)) for _ in range(N)]

ta = [[0]*14 for _ in range(14)]
dp = [[0]*14 for _ in range(14)]

for a in A:
  m2 = power_mod(a,2)
  m5 = power_mod(a,5)
  ta[m2][m5] += 1
  dp[m2][m5] += 1
  
for i in range(13):
  dp[13][12-i] = dp[13][12-i] + dp[13][13-i]
  dp[12-i][13] = dp[12-i][13] + dp[13-i][13]
  
for i in range(13):
  for j in range(13):
    dp[12-i][12-j] = dp[12-i][12-j]+ dp[12-i][13-j] + dp[13-i][12-j] - dp[13-i][13-j]

#for t in ta:
#  print(t)
#for d in dp:
#  print(d)
  
ans = 0
for i in range(5,14):
  for j in range(5,14):
    #if ta[i][j]:
    #  print(i,j,ta[i][j],dp[max(0, 18-i)][max(0,18-j)],((i>8) and (j>8)))
    ans += ta[i][j] * (dp[max(0, 18-i)][max(0,18-j)] - ((i>8) and (j>8)))
    
print(ans//2)

Submission status: Runtime Error

Solution code:
import math
x = int(input())

A = []
for i in range(0, int(x)):
  val = int(input(""))
  if val:
      A.append(val)

p = 0
for i in range(int(x)):
    for t in range(int(x)):
        if (i - t > 0) and float(A[i])*float(A[t]) == math.floor(float(A[i])*float(A[t])):
             p += 1
            
print(p)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
import copy
n = int(input())
l = []
for i in range(n):
    a = str(input())
    if "." not in a:
        l.append(Decimal(a))
    else:
        dot = a.index(".")
        if len(a)-dot-1 <= 4:
            l.append(Decimal(a))
        else:
            flag = 1
            for j in range(dot+5,len(a)):
                if a[j] != "0":
                    flag = 0
            if flag: l.append(Decimal(a)) 
n = len(l)
a = [int(l[i]*10**4) for i in range(n)]
memo = [[0,0] for _ in range(n)]
for i in range(n):
    t = a[i]
    while t%2 == 0:
        t //= 2
        memo[i][0] += 1
    while t%5 == 0:
        t //= 5
        memo[i][1] += 1
a.sort()
memo.sort()
mem2 = [[0]*9 for _ in range(9)]
p = 0
for i in range(n):
    if memo[i][0] >= 8 and memo[i][1] >= 8:
        p += 1
    else:
        mem2[memo[i][0]][memo[i][1]] += 1
mems = copy.deepcopy(mem2)


for i in range(8,-1,-1):
    for j in range(7,-1,-1):
        mems[i][j] += mems[i][j+1]
for i in range(7,-1,-1):
    for j in range(8,-1,-1):
        mems[i][j] += mems[i+1][j]

s = 0
for i in range(9):
    for j in range(9):
        if i >= 4 and j >= 4:
            s += mem2[i][j] * (mems[8-i][8-j]-1)
        else:
            s += mem2[i][j] * mems[8-i][8-j]
s = s//2
s += p*(p-1)//2+p*(n-p)
print(s)

Submission status: Runtime Error

Solution code:
n=int(input())
G=[[0]*20 for i in range(25)]
A=[0,0,0,0]
for i in range(n):
  S=list(input())
  s=""
  f=0
  a=0
  for j in S:
    if j==".":
      f=1
    else:
      s=s+j
      if f==1:
        a=a+1
  A[0]=int(s)
  A[1]=a
  m=int(s)
  c=0
  while m%10==0:
    c=c+1
    m=m//10
  A[0]=m
  A[1]-=c
  m=A[0]
  c=0
  while m%2==0:
    c=c+1
    m=m//2
  A[2]=c
  c=0
  m=A[0]
  while m%5==0:
    c=c+1
    m=m//5
  A[3]=c
  G[A[2]-A[1]+9][A[3]-A[1]+9]+=1
B=[[0]*21 for i in range(26)]
for i in range(24,-1,-1):
  for j in range(19,-1,-1):
    B[i][j]=B[i+1][j]+B[i][j+1]-B[i+1][j+1]+G[i][j]
ans=0
for i in range(25):
  for j in range(20):
    ans=ans+G[i][j]*B[max(0,18-i)][max(0,18-j)]
    if i>=max(0,18-i) and j>=max(0,18-j):
      ans=ans-G[i][j]
print(ans//2)

Submission status: Runtime Error

Solution code:
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

OFS=20
KK = 41
n = inn()
d = [[0]*KK for i in range(KK)]
for i in range(n):
    a = ins()
    p = a.find('.')
    if p<0:
        v = int(a)
        k = 0
    else:
        b = a[:p]+a[p+1:]
        v = int(b)
        k = len(a)-1-p
    x2 = 0
    while v%2==0:
        x2 += 1
        v //= 2
    x5 = 0
    while v%5==0:
        x5 += 1
        v //= 5
    d[x2-k+OFS][x5-k+OFS] += 1

#if DBG:
#    for i in range(KK):
#        for j in range(KK):
#            if d[i][j]!=0:
#                ddprint(f"i {i-OFS} j {j-OFS} {d[i][j]}")

ans = 0
h = {}
for p in range(KK):
    for q in range(KK):
        sm = 0 if p<OFS or q<OFS else (d[p][q]*(d[p][q]-1)//2)
        #if sm>0:
        #ddprint(f"p {p-OFS} q {q-OFS} d {d[p][q]} {sm=}")
        for r in range(-p+2*OFS,KK):
            #if r==p:
            #    continue
            for s in range(-q+2*OFS,KK):
                if (r,s)==(p,q) or (r,s,p,q) in h:
                    continue
                h[(p,q,r,s)] = 1
                sm += d[p][q]*d[r][s]
                #if d[p][q]*d[r][s]>0:
                #    ddprint(f"p {p-OFS} q {q-OFS} r {r-OFS} s {s-OFS} d {d[p][q]} {d[r][s]}")
        ans += sm
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math

n = int(input())
a_top = [[], []]
a_base = [[], []]
for _ in range(n):
    s = input().rstrip()
    if "." not in s:
        top = int(s)
        base = 1
    else:
        dot = s.index(".")
        length = len(s)
        lower_num = len(s) - dot - 1
        top = int(s.replace(".", ""))
        base = pow(10, lower_num)
    gcd = math.gcd(top, base)
    top = top // gcd
    base = base // gcd
    twos = 0
    fives = 0
    while top % 2 == 0:
        twos += 1
        top //= 2
    while top % 5 == 0:
        fives += 1
        top //= 5
    a_top[0].append(twos)
    a_top[1].append(fives)
    twos = 0; fives = 0
    while base % 2 == 0:
        twos += 1
        base //= 2
    while base % 5 == 0:
        fives += 1
        base //= 5
    a_base[0].append(twos)
    a_base[1].append(fives)

nums = dict()
offset = 16
field = [[0] * 35 for _ in range(35)]
for tt, tf, bt, bf in zip(a_top[0], a_top[1], a_base[0], a_base[1]):
    field[tt - bt + offset][tf - bf + offset] += 1

single = 0
double = 0
for i in range(35):
    for j in range(35):
        for k in range(35):
            for l in range(35):
                if i == k and j == l:
                    if i - offset + k - offset >= 0 and j - offset + l - offset >= 0:
                        double += field[i][j] * (field[i][j] - 1)
                else:
                    if i - offset + k - offset >= 0 and j - offset + l - offset >= 0:
                        double += field[i][j] * field[k][l]
print(single + double // 2)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import math

n = int(input())
a_top = [[], []]
a_base = [[], []]
for _ in range(n):
    s = input().rstrip()
    if "." not in s:
        top = int(s)
        base = 1
    else:
        dot = s.index(".")
        length = len(s)
        lower_num = len(s) - dot - 1
        top = int(s.replace(".", ""))
        base = pow(10, lower_num)
    gcd = math.gcd(top, base)
    top = top // gcd
    base = base // gcd
    twos = 0
    fives = 0
    while top % 2 == 0:
        twos += 1
        top //= 2
    while top % 5 == 0:
        fives += 1
        top //= 5
    a_top[0].append(twos)
    a_top[1].append(fives)
    twos = 0; fives = 0
    while base % 2 == 0:
        twos += 1
        base //= 2
    while base % 5 == 0:
        fives += 1
        base //= 5
    a_base[0].append(twos)
    a_base[1].append(fives)

nums = dict()
offset = 10
field = [[0] * 22 for _ in range(22)]
for tt, tf, bt, bf in zip(a_top[0], a_top[1], a_base[0], a_base[1]):
    field[tt - bt + offset][tf - bf + offset] += 1

single = 0
double = 0
for i in range(22):
    for j in range(22):
        for k in range(22):
            for l in range(22):
                if i == k and j == l:
                    if i - offset + k - offset >= 0 and j - offset + l - offset >= 0:
                        double += field[i][j] * (field[i][j] - 1)
                else:
                    if i - offset + k - offset >= 0 and j - offset + l - offset >= 0:
                        double += field[i][j] * field[k][l]
print(single + double // 2)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
li = []
for i in range(n):
    s = input()
    if '.' in s:
        a, b = s.split('.')
        t = 10 ** len(b)
        li.append((int(a) * t + int(b), t))
    else:
        li.append((int(s), 1))
p = [[0] * 30 for _ in range(30)]
cnt = 0
for i in range(n):
    x, y = li[i]
    g = gcd(x, y)
    x //= g
    y //= g
    if y == 1:
        cnt += 1
    li[i] = x
    a1, b1 = 0, 0
    while x % 2 == 0:
        a1 += 1
        x //= 2
    while x % 5 == 0:
        b1 += 1
        x //= 5
    a2, b2 = 0, 0
    while y % 2 == 0:
        a2 += 1
        y //= 2
    while y % 5 == 0:
        b2 += 1
        y //= 5
    p[a1 - a2 + 9][b1 - b2 + 9] += 1
ans = 0
for i in range(0, 30):
    for j in range(0, 30):
        for a in range(max(0, 18 - i), 30):
            for b in range(max(0, 18 - j), 30):
                ans += p[i][j] * p[a][b]
print((ans - cnt) // 2)

Submission status: Runtime Error

Solution code:
# 行数
N = int(input().strip())

# 2次元配列
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

count=0
j=1
l=0
while l <= N:
    while j <= N:
        if grid[l]*grid[j]-int(grid[l]*grid[j]) == 0:
            count = count + 1
        j=j+1
        if j == N+1 and l<N:
            l=l+1
            j=l+1

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = round(float(input())*(10**9))
floatans=0
for i in range(N):
    for j in range(i+1,N):
        a = floor(A[i] * A[j])
        if a%(10**18)==0:
            floatans+=1
print(floatans)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
li = []
for i in range(n):
    s = input()
    if '.' in s:
        a, b = s.split('.')
        t = 10 ** len(b)
        li.append((int(a) * t + int(b), t))
    else:
        li.append((int(s), 1))
p = [[0] * 24 for _ in range(24)]
cnt = 0
for i in range(n):
    x, y = li[i]
    g = gcd(x, y)
    x //= g
    y //= g
    if y == 1:
        cnt += 1
    li[i] = x
    a1, b1 = 0, 0
    while x % 2 == 0:
        a1 += 1
        x //= 2
    while x % 5 == 0:
        b1 += 1
        x //= 5
    a2, b2 = 0, 0
    while y % 2 == 0:
        a2 += 1
        y //= 2
    while y % 5 == 0:
        b2 += 1
        y //= 5
    p[a1 - a2 + 9][b1 - b2 + 9] += 1
ans = 0
for i in range(0, 24):
    for j in range(0, 24):
        for a in range(max(0, 18 - i), 24):
            for b in range(max(0, 18 - j), 24):
                ans += p[i][j] * p[a][b]
print((ans - cnt) // 2)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = float(input())
floatans=0
for i in range(N):
    for j in range(i+1,N):
        x = round(A[i]*(10**9))
        y = round(A[j]*(10**9))
        a = floor(x * y)
        if a%(10**18)==0:
            floatans+=1
print(floatans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def primes(n):
    a = Counter()
    while n % 2 == 0:
        a[2]+=1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a[f]+=1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n]+=1
    return a

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(str, input().split())) #1行ベクトル
    A = tuple(input() for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    dp=[[0]*19 for _ in range(19)]
    for a in A:
        ta=0
        base=1
        dot=0
        for i in range(len(a)):
            ai=a[-1-i]
            if ai==".":
                dot=i
            else:
                ta+=base*int(ai)
                base*=10
        
        c=primes(ta)
        n2=min(18,c[2])+(9-dot)
        n5=min(18,c[5])+(9-dot)
        t2=18-n2
        t5=18-n5
        for i in range(t2,19):
            for j in range(t5,19):
                ans+=dp[i][j]
        #printe(n2,n5,ans)
        dp[n2][n5]+=1
    print(ans)




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
alst = [float(input()) for _ in range(n)]

int_cnt = 0
lst = [[0 for _ in range(10)] for _ in range(10)]
lst2 = [[0 for _ in range(20)] for _ in range(30)]
for num in alst:
    if num % 1 == 0:
        int_cnt += 1
        b = 0
        f = 0
        while num % 2 == 0:
            b += 1
            num //= 2
        while num % 5 == 0:
            f += 1
            num //= 5
        b = min(9, b)
        lst[b][f] += 1
    else:
        num *= 10 ** 9
        b = 1
        f = 1
        while num % 2 == 0:
            f += 1
            num //= 2
        while num % 5 == 0:
            b += 1
            num //= 5
        lst2[b][f] += 1

ans = int_cnt * (int_cnt - 1) // 2

for i in range(10):
    for j in range(10):
        cnt = 0
        for k in range(max(10 - i, 0), 30):
            for l in range(10 - j, 20):
                cnt += lst2[k][l]
        ans += lst[i][j] * cnt

cnt = 0
for i in range(11, 20):
    for j in range(20):
        cnt += lst2[i][j]

cnt2 = 0
for i in range(11, 20):
    for j in range(30):
        cnt2 += lst2[j][i]

ans += cnt * cnt2
print(ans)

Submission status: Runtime Error

Solution code:
from math import *
import sys 
cin = sys.stdin()

cnt = [[0] * 19 for i in range(19)]

ans = 0
for _ in range(int(input())):
    t = float(input())
    b = int(t * 1000000000.0)
    x, y = 0, 0
    while b % 2 == 0 and x < 18:
        x += 1
        b //= 2
    while b % 5 == 0 and y < 18:
        y += 1
        b //= 5
    #print(x, y)
    for i in range(19):
        for j in range(19):
            if i + x >= 18 and j + y >= 18:
                ans += cnt[i][j]
    cnt[x][y] += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import decimal
import numpy as np
input = sys.stdin.readline

N = int(input())
A = []
C2 = np.array([[0 for j in range(14)] for i in range(14)])  # 10countは9タス
C5 = np.array([[0 for j in range(14)] for i in range(14)])
C10 = np.zeros(14)
for _ in range(N):
    i = decimal.Decimal(input())
    c10, c2, c5 = 0, 0, 0
    while i % 1 != 0:
        c10 -= 1
        i *= 10
    while i % 10 == 0:
        c10 += 1
        i /= 10
    while i % 2 == 0:
        c2 += 1
        i /= 2
    while i % 5 == 0:
        c5 += 1
        i /= 5
    c2 = min(c2, 13)
    c5 = min(c5, 13)
    A.append((c10, c2, c5))
    C2[c10+9][c2] += 1
    C5[c10+9][c5] += 1
    C10[c10+9] += 1

for i in range(14):
    for j in range(12, -1, -1):
        C2[i][j] += C2[i][j + 1]
        C5[i][j] += C5[i][j + 1]
for i in range(12, -1, -1):
    C10[i] += C10[i+1]

ans = 0
for c10, c2, c5 in A:
    if c10 >= 0:
        ans -= 1
    if c10>=-4:
        ans += C10[-c10 + 9]
    if c5 == 0:
        for i in range(-c10 + 9):
            shouldhave = (-c10+9) - i
            if shouldhave <= c2:
                ans += C5[i][shouldhave]
    elif c2 == 0:
        for i in range(-c10 + 9):
            shouldhave = (-c10 + 9) - i
            if shouldhave <= c5:
                ans += C2[i][shouldhave]
print(int(ans//2))

Submission status: Runtime Error

Solution code:
from math import gcd
from collections import defaultdict
n = int(input())
N = 30
a = [[0 for i in range(N)] for j in range(N)]
p = pow(10,9)
two_size = 18
five_size = 18
count = 0
for i in range(n):
    k = float(input()) * p
    two = 0
    five = 0
    while k % 2 == 0:
        two += 1
        k //= 2
    while k % 5 == 0:
        five += 1
        k //= 5
    t, f = two_size - two, five_size - five
    for x in range(t, N):
        for y in range(f, N):
            count += a[x][y]
    a[two][five] += 1
print(count)

Submission status: Runtime Error

Solution code:
import sys
import math
import bisect

def query_value(s):
    #print('s: %s' % s)
    pos = s.find('.')
    if (pos == -1):
        return int(s) * 10 ** 9
    ans = int(s[:pos])
    #print('ans: %d' % ans)
    for i in range(pos + 1, pos + 10):
        #print('i: %d' % i)
        #print('len(%s): %d' % (s, len(s)))
        if i >= len(s):
            ans *= 10
        else:
            #print('s[%d] = %s' % (i, s[i]))
            ans = ans * 10 + ord(s[i]) - ord('0')
            #ans *= 10
    return ans

def main():
    n = 18
    A = []
    for i in range(n):
        A.append([0] * n)
    #print('A: %s' % str(A))
    for _ in range(int(input())):
        a = query_value(input())
        #print('a: %d' % a)
        p2 = 0
        p5 = 0
        while a % 2 == 0:
            p2 += 1
            a /= 2
        while a % 5 == 0:
            p5 += 1
            a /= 5
        A[p2][p5] += 1
        #print('p2: %d, p5: %d' % (p2, p5))
    ans = 0
    for x1 in range(n):
        for y1 in range(n):
            for x2 in range(n):
                for y2 in range(n):
                    if x1 == x2 and y1 == y2:
                        if A[x1][y1] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * (A[x2][y2] - 1)
                            #print('ans: %d' % ans)
                    else:
                        if A[x1][y1] > 0 and A[x2][y2] > 0 and x1 + x2 >= n and y1 + y2 >= n:
                            #print('A[%d][%d]: %d, A[%d][%d]: %d' % (x1, y1, A[x1][y1], x2, y2, A[x2][y2]))
                            ans += A[x1][y1] * A[x2][y2]
                            #print('ans: %d' % ans)
    ans //= 2
    print(ans)
    '''
    for i in range(n):
        print('A[%d]: %s' % (i, str(A[i])))
    '''

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from math import *

cnt = [[0] * 19 for i in range(19)]

ans = 0
for _ in range(int(input())):
    t = float(input())
    b = int(t * 1000000000.0)
    x, y = 0, 0
    while b % 2 == 0 and x <= 18:
        x += 1
        b //= 2
    while b % 5 == 0 and y <= 18:
        y += 1
        b //= 5
    #print(x, y)
    for i in range(19):
        for j in range(19):
            if i + x >= 18 and j + y >= 18:
                ans += cnt[i][j]
    cnt[x][y] += 1
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    n = ii()
    a = []
    ans = 0
    for i in range(n):
        tmp = input()
        ketaage = 0
        if '.' in tmp:
            cnt = 1
            while tmp[-cnt] != '.':
                cnt += 1
            ketaage = cnt - 1
            tmp = tmp[:-cnt] + tmp[-cnt + 1:]
        tmp = int(tmp)
        while tmp % 10 == 0:
            ketaage -= 1
            tmp //= 10
        tcnt = 0
        fcnt = 0
        while tmp % 2 == 0:
            tcnt += 1
            tmp //= 2
        if tcnt == 0:
            while tmp % 5 == 0:
                fcnt += 1
                tmp //= 5
        a.append([tcnt, fcnt, ketaage])
    tlist = []
    flist = [[0 for i in range(40)] for j in range(30)]
    tlistlist = [0 for i in range(40)]

    seisuucnt = 0
    fseisuucnt = 0

    for i in range(n):
        if a[i][1] == 0:
            tlist.append([a[i][0], a[i][2]])

            if a[i][2] <= 0:
                seisuucnt += 1
                tlistlist[a[i][2] + 20] += 1
        else:
            flist[a[i][2] + 20][a[i][1]] += 1
            if a[i][2] <= 0:
                fseisuucnt += 1
    for i in range(1, 30):
        tlistlist[i] += tlistlist[i - 1]

    for tmp in range(30):
        for i in range(1, 40):
            flist[tmp][39 - i] += flist[tmp][39 - i + 1]
    for tmp in tlist:
        keta = tmp[1]
        tcnt = tmp[0]
        for i in range(-5, 22):
            if keta + i > tcnt:
                break
            ans += flist[i + 20][max(0, keta + i)]


#            print(tmp, keta, i, flist[i + 10][max(0, keta + i)],
#                  tlistlist[10 - keta])
        ans += tlistlist[20 - keta]

    if seisuucnt > 0:
        ans -= (seisuucnt * (seisuucnt - 1)) // 2
        ans -= seisuucnt
    if fseisuucnt > 0:
        ans += (fseisuucnt * (fseisuucnt - 1)) // 2
    print(ans)

main()

Submission status: Runtime Error

Solution code:
from math import *

cnt = [[0] * 19 for i in range(19)]

ans = 0
for _ in range(int(input())):
    t = float(input())
    b = int(t * 1000000000.0)
    x, y = 0, 0
    while b % 2 == 0 and x <= 18:
        x += 1
        b //= 2
    while b % 5 == 0 and x <= 18:
        y += 1
        b //= 5
    #print(x, y)
    for i in range(19):
        for j in range(19):
            if i + x >= 18 and j + y >= 18:
                ans += cnt[i][j]
    cnt[x][y] += 1
print(ans)