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:
def a():
    nums=[]
    count=0
    for i in range(0,200001):
        s=input()
        if s != "":
            nums.append(s)
        else:
            break
#
    for i in range(len(nums)):
        nums[i]=float(nums[i])
    print(nums)
#
    for i in range(1,len(nums)-1):
        if 1==1:
            for t in range(i+1,len(nums)):
                r=nums[i]*nums[t]
                if nums[i]*nums[t]==int(nums[i]*nums[t]):
                    print(nums[i])
                    print(nums[t])
                    print(nums[i]*nums[t])
                    count+=1
    return count
  
 a()

Submission status: Runtime Error

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [[0] * 18 for _ in range(26)]
    ans = 0
    for _ in range(n):
        S = input()
        if '.' in S:
            a, b = S.split('.')
            a = int(a + b + '0' * (9 - len(b)))
        else:
            a = int(S + '0' * 9)
        two = five = 0
        while a % 2 == 0:
            two += 1
            a //= 2
        while a % 5 == 0:
            five += 1
            a //= 5
        for i in range(26):
            for j in range(18):
                if i + two >= 18 and j + five >= 18:
                    ans += counter[i][j]
        counter[two][five] += 1
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [[0] * 16 for _ in range(24)]
    ans = 0
    for _ in range(n):
        S = input()
        if '.' in S:
            a, b = S.split('.')
            a = int(a + b + '0' * (9 - len(b)))
        else:
            a = int(S + '0' * 9)
        two = five = 0
        while a % 2 == 0:
            two += 1
            a //= 2
        while a % 5 == 0:
            five += 1
            a //= 5
        for i in range(24):
            for j in range(16):
                if i + two >= 18 and j + five >= 18:
                    ans += counter[i][j]
        counter[two][five] += 1
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
from decimal import Decimal
from numba import njit, i4, i8


@njit(i8(i8, i4), cache=True)
def div(n, d):
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


@njit(cache=True)
def solve(arr):
    ans = 0
    for i in range(len(arr)):
        for j in range(i + 1, len(arr)):
            (a, b), (c, d) = arr[i], arr[j]
            if a + c >= 18 and b + d >= 18:
                ans += 1
    return ans


n = int(input())
arr = [int(Decimal(input()) * 10**9) for _ in range(n)]
arr = [(div(x, 2), div(x, 5)) for x in arr]

print(solve(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
A=[]

bo=[[0 for i in range(19)] for i in range(19)]
stc=[]
natu=0

def nankai(x,d):
    cnt=0
    while x%d==0 and x>=1:
       cnt+=1
       x=x//d
    return cnt

def bonankai(p,q):
    return nankai(p,2)-nankai(q,2)+9,nankai(p,5)-nankai(q,5)+9


for i in range(n):
    r=input()
    if "." in r:
        tag=r.index(".")
        p=int(r[:tag]+r[tag+1:])
        q=pow(10,len(r[tag+1:]))
        res=bonankai(p,q)
        bo[res[0]][res[1]]+=1
        #print(p,q)
        stc.append(res)
    else:
        p=int(r)
        q=1
        res=bonankai(p,q)
        bo[res[0]][res[1]]+=1
        #print(p,q)
        stc.append(res)
        natu+=1

for i in range(17,-1,-1):
    for q in range(19):
        bo[i][q]+=bo[i+1][q]

for q in range(17,-1,-1):
    for i in range(19):
        bo[i][q]+=bo[i][q+1]

ans=0
for que in stc:
    ans+=bo[18-que[0]][18-que[1]]
ans-=natu
ans//=2
print(ans)

Submission status: Runtime Error

Solution code:
    n= int(input())
     
    arr = [float(input(x)) for _ in range(n)]
    c = 0
     
    for i in range(n):
      for j in range(i+1,n):
        s = arr[i]/arr[j]
        if s==int(s):
          c+=1
          
    print(ans)

Submission status: Runtime Error

Solution code:
n= int(input())

arr = [float(input(x)) for _ in range(n)]
c = 0

for i in range(n):
  for j in range(i+1,n):
    if i/j==i//j:
      c+=1
      
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
count=0
l=list(map(int,input().split("\n")))
for i in range(len(l)):
  for j in range(len(l)):
    if(i==j):
      continue
    else:
      if((l[i]*l[j]).is_integer()):
        count+=1

Submission status: Runtime Error

Solution code:
from numba import njit


@njit
def div(n):
    n = int(n)
    two = format(n, 'b')[::-1].find('1')
    if two < 0:
        return(-1, -1)
    n = n >> two
    cnt = 0
    while n % 5 == 0:
        n //= 5
        cnt += 1
    return (two, cnt)


n = int(input())
arr = [div(int(float(input()) * 10**9)) for _ in range(n)]

ans = 0
for i in range(len(arr)):
    for j in range(i + 1, len(arr)):
        (a, b), (c, d) = arr[i], arr[j]
        if a + c >= 18 and b + d >= 18:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [[0] * 16 for _ in range(24)] # -9 ~ 13, -9 ~ 5
    ans = 0
    for _ in range(n):
        S = input()
        if '.' in S:
            a, b = S.split('.')
            two = five = -len(b)
            a = int(a + b)
        else:
            two = five = 0
            a = int(S)
        while a % 2 == 0:
            two += 1
            a //= 2
        while a % 5 == 0:
            five += 1
            a //= 5
        for i in range(-9, 14):
            for j in range(-9, 6):
                if two + i >= 0 and five + j >= 0:
                    ans += counter[i][j]
        counter[two][five] += 1
    print(ans)
resolve()

Submission status: Runtime Error

Solution code:
def fact2(a, b):
    c2 = 0
    c5 = 0
    while a%2 == 0:
        a //= 2
        c2 += 1
    while a%5 == 0:
        a //= 5
        c5 += 1
    return min(c2-b, 9), min(c5-b,9)

def main():
    N = int( input())
    A2 = [0]*N
    A5 = [0]*N
    AS = [0]*N
    for i in range(N):
        a = input()
        if '.' in a:
            b, c = a.split('.')
            if int(c) == 0:
                pass
            else:
                c = chr( int(c))
                AS[i] = len(c)
                b += c
        else:
            b = a
        # A2[i], A5[i] = fact( int(b))
        # print(b)
        A2[i], A5[i] = fact2( int(b), AS[i])

    R = [ [0]*19 for _ in range(19)]
    for i in range(N):
        a, b = A5[i]+9, A2[i]+9
        R[a][b] += 1
    AR = [ [0]*19 for _ in range(19)]
    for i in range(18,-1,-1):
        for j in range(17,-1,-1):
            R[i][j] = R[i][j] + R[i][j+1]
    for j in range(18):
        for i in range(17,-1,-1):
            R[i][j] += R[i+1][j]
    ans = 0
    # print("\n".join( [" ".join( map( str, a)) for a in AR]))
    for k in range(N):
        i, j = A5[k], A2[k]
        if i <= 9 and j <= 9:
            ans += R[-i+9][-j+9]
            # print(-i+9,-j+9)
        if AS[k] == 0:
            ans -= 1
    print(ans//2)

# 2
# 10.73741824 
# 3051.7578125
# 2**30, 2**15

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*20 for _ in [0]*20]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (min(19,i),min(19,j))
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*20 for _ in [0]*20]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (max(19,i),max(19,j))
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Runtime Error

Solution code:
N = int(input())
X = [input() for i in range(N)]
k = 0
j = 1 
total = 0
while j<=N-1:
    while k<j:
        A = float(X[k])
        B = float(X[j])
        C = A*B
        D = C.is_integer()
        if C = 0.999999999*1.000000001:
            total += 0
        elif D == True:
            total += 1
        else:
            total += 0
        k += 1
    j += 1
    k = 0
print(total)

Submission status: Runtime Error

Solution code:
N = int(input())

li_01 = []
li_001 = []
li_0001 = []
li_00001 = []
integer = []

for _ in range(N):
    num = float(input())
    if round(num * 10, 7) % 10 == 0:
        integer.append(num)
        
    else:
        if round(num * 10**2, 7) % 10 == 0:
            li_01.append(num)
        elif round(num * 10**3, 7) % 10 == 0:
            li_001.append(num)
        elif round(num * 10**4,7) % 10 == 0:
            li_0001.append(num)
        elif round(num * 10**5,7) % 10 == 0:
            li_00001.append(num)

            
int_len = len(integer)
count = int_len * (int_len - 1) / 2

print(li_01)

int_101 = []
int_102 = []
int_103 = []
int_104 = []
int_1 = []


for num in integer:
    if num % 10**3 == 0.0:
        int_103.append(num)
    elif num % 10**2 == 0.0:
        int_102.append(num)
    elif num % 10 == 0.0:
        int_101.append(num)
    else:
        int_1.append(num)
        
for num103 in int_103:
    for num_00001 in li_00001:
        if round(num3 * num_00001 * 10, 7) % 10 == 0.0:
            count += 1
            
count += len(int_103) * len(li_0001)

for num102 in int_102:
    for num_0001 in li_0001:
        if round(num102 * num_0001 * 10, 7) % 10 == 0:
            count += 1
            
count += (len(int_103) + len(int_102)) * len(li_001)

for num101 in int_102:
    for num_001 in li_001:
        if round(num101 * num_001 * 10,7) % 10 == 0:
            count += 1
            
count += (len(int_103) + len(int_102) + len(int_101)) * len(li_01)

for num1 in int_1:
    for num_01 in li_01:
        if (num1 * num_01 * 10) % 10 == 0:
            count += 1
cnt = 0            
for num_01 in li_01:
    for num__01 in li_01:
        if (num_01 * num__01 * 10) % 10 == 0:
            cnt += 1
            
for num_001 in li_001:
    if num_001 % 1 == 0.25 or num_001 % 0.75:
        for num_1 in int_1:
            if num_1 % 4 == 0:
                count += 1

for num_0001 in li_0001:
    if num_0001 % 1 == 0.025 or num_0001 % 0.075:
        for num_10 in int_101:
            if num_10 % 40 == 0:
                count += 1
                
for num_00001 in li_00001:
    if num_00001 % 1 == 0.0025 or num_0001 % 0.0075:
        for num_100 in int_102:
            if num_10 % 400 == 0:
                count += 1


count += cnt / 2            
            
print(count)

Submission status: Runtime Error

Solution code:
from fractions import Fraction
from decimal import Decimal

n=int(input())
a=[Fraction(Decimal(input())) for _ in range(n)]

num=[aa.numerator*10**9//aa.denominator for aa in a]

cnt=[[0]*20 for _ in range(20)]
pair=[]

for nu in num:
    c2=0
    c5=0
    while nu>0 and nu%2==0:
        nu//=2
        c2+=1
    
    while nu>0 and nu%5==0:
        nu//=5
        c5+=1
    
    cnt[c2][c5]+=1
    pair.append((c2,c5))
ans=0

for c2,c5 in pair:
    for cc2 in range(18-c2,20):
        for cc5 in range(18-c5,20):
            ans+=cnt[cc2][cc5]
    if c2>=9 and c5>=9:
        ans-=1

print(ans//2)

Submission status: Runtime Error

Solution code:

N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*20 for _ in [0]*20]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (i,j)
    cnt[i][j] += 1
exit()

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*20 for _ in [0]*20]
B = [(0,0)]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (i,j)
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Runtime Error

Solution code:
N = int(input())
import decimal
a = [decimal.Decimal(input()) for i in range(N)]
count = 0


for i in range(N):
    for j in range(N):
            if i < j:
            if a[i]-int(a[i])==0 and a[j]-int(a[j])==0:
                count += 1
                continue
            kakeru = a[i]*a[j]
            if kakeru - int(kakeru) == 0:
                count += 1

print(count)

Submission status: Runtime Error

Solution code:
from fractions import Fraction
from decimal import Decimal

n=int(input())
a=[Fraction(Decimal(input())) for _ in range(n)]

num=[aa.numerator*10**9//aa.denominator for aa in a]

cnt=[[0]*15 for _ in range(15)]
pair=[]

for nu in num:
    c2=0
    c5=0
    while nu%2==0:
        nu//=2
        c2+=1
    
    while nu%5==0:
        nu//=5
        c5+=1
    
    cnt[c2][c5]+=1
    pair.append((c2,c5))
ans=0

for c2,c5 in pair:
    for cc2 in range(18-c2,15):
        for cc5 in range(18-c5,15):
            ans+=cnt[cc2][cc5]
    if c2>=9 and c5>=9:
        ans-=1

print(ans//2)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [input() for _ in [0]*N]

for i,a in enumerate(A):
    b = a.split(".")
    if len(b)==1:
        A[i] = int(a)*10**9
        continue
    c = b[1]
    n = len(c)
    c += "0"*(9-n)
    A[i] = int(b[0] + c)

cnt = [[0]*20 for _ in [0]*20]
B = [None]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (i,j)
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Runtime Error

Solution code:
import sys
import decimal

input = sys.stdin.readline
D = decimal.Decimal


def power_2_5(arg):
    n, d = D(arg).as_integer_ratio()

    p2 = 0
    p5 = 0
    for i in range(10):
        if n % 2 == 0:
            n //= 2
            p2 += 1
        else:
            break
    for i in range(10):
        if n % 5 == 0:
            n //= 5
            p5 += 1
        else:
            break
    for i in range(10):
        if d % 2 == 0:
            d //= 2
            p2 -= 1
        else:
            break
    for i in range(10):
        if d % 5 == 0:
            d //= 5
            p5 -= 1
        else:
            break
    return p2, p5


N = int(input())

P = [power_2_5(input()) for _ in range(N)]

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

for p2, p5 in P:
    arr[p2 + 9][p5 + 9] += 1

cum_arr = [[0] * 19 for _ in range(19)]
for i in range(19):
    cum_arr[-1][i] = arr[-1][i]
    cum_arr[i][-1] = arr[i][-1]
for i in reversed(range(18)):
    for j in reversed(range(18)):
        cum_arr[i][j] = (
            arr[i][j] + cum_arr[i][j + 1] + cum_arr[i + 1][j] - cum_arr[i + 1][j + 1]
        )

ans = -cum_arr[9][9]
for i in range(19):
    for j in range(19):
        ans += arr[i][j] * cum_arr[18 - i][18 - j]

ans //= 2

print(ans)

Submission status: Runtime Error

Solution code:
def prime(n):
    ans=[0,0]
    n*=10**9
    while n>0:
        if n%2==0:
            ans[0]+=1
            n//=2
        elif n%5==0:
            ans[1]+=1
            n//=5
        else:
            break
    ans[0]-=9
    ans[1]-=9
    return ans

n=int(input())
a=[float(input()) for _ in range(n)]
b=[prime(a[i]) for i in range(n)]
ans=0
c=[s for s in b if (2**max([0,-s[0]]))*(5**max([0,-s[1]]))<10**4]

d=[[0 for k in range(-9,14)] for l in range(-5,6)]

for i in range(len(c)):
    for k in range(-9,14):
        for l in range(-5,6):
            if c[i][0]>=k and c[i][1]>=l:
                d[l+5][k+13]+=1

for i in range(len(c)):
    ans+=d[-c[i][1]+5][-c[i][0]+13]
    if c[i][0]>=0 and c[i][1]>=0:
        ans-=1
print(ans//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):
    b_int, b_frac = str(A[i]).split(".")
    if len(b_frac)>4 and A[i].is_integer()==False:
        continue
    for j in range(i+1,N):
        c_int, c_frac = str(A[j]).split(".")
        if A[j].is_integer()==False and (len(c_frac)>4 or len(b_int)<len(c_frac)):
            continue
        if (round(A[i]*(10**4))*round(A[j]*(10**4)))%(10**8)==0:
            floatans+=1
print(floatans)

Submission status: Runtime Error

Solution code:
import psyco
psyco.full()
N = int(input())
sum = []
for i in range(N):
    s = input()
    if '.' in s:
        s = float(s)
        sum.append(s)
    else:
        s = int(s)
        sum.append(s)
count = 0
for i in range(len(sum)):
    for j in range(len(sum)):
        if i < j and sum[i]!=sum[j]:
            a = sum[i]*sum[j] 
            if a == int(a):
                count+=1
print(count)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
n=int(input)
A=[float(input) for _ in range(n)]
multiple=[]
count=0
for i in range(1,n):
    for j in range(n-i):
        ans=Decimal(A[i-1]*A[i+j])
        if float(ans).is_integer():
            multiple.append(ans)
        count+=1
print(len(multiple))

Submission status: Runtime Error

Solution code:
from fractions import Fraction

n=int(input())

num=[]
twoP=[]
fiveP=[]
e=[]

num_num=[[0 for i in range(6)]for j in range(6)]
two_num=[0 for i in range(60)]
five_num=[0 for i in range(60)]


for i in range(n):
    s=input()
    if "." in s: 
        b=len(s.split(".")[1])
    else:
        b=0
    s=int(s.replace(".",""))
    a=Fraction(s,10**b)

    if a.denominator==1:
        num.append(a)
        c=a.numerator
        two=0
        five=0
        while c%2==0:
            c//=2
            two+=1
        while c%5==0:
            c//=5
            five+=1

        num_num[two][five]+=1
        two_num[two]+=1
        five_num[five]+=1
    elif a.denominator%2==0 and a.denominator%5==0:
        e.append(a)
    elif a.denominator%5==0:
        fiveP.append(a)
        c=a.numerator
        two=0
        # while c%2==0:
        #     c//=2
        #     two+=1
        # two_num[two]+=1

    else:
        twoP.append(a)
        c=a.numerator
        five=0
        # while c%5==0:
        #     c//=5
        #     five+=1
        # five_num[five]+=1
ans= len(num)*(len(num)-1)//2
# print(ans)
for a in twoP:
    c=a.denominator
    count=0
    while c%2==0:
        count+=1
        c//=2
    # print(count,c)
    if count>=50:
        continue
    for i in range(count,50):
        ans+=two_num[i]
# print(ans)
for a in fiveP:
    c=a.denominator
    count=0
    while c%5==0:
        count+=1
        c//=5
    if count>=49:
        continue
    for i in range(count,50):
        ans +=five_num[i]
# print(ans)
for a in e:
    c=a.denominator
    c2,c5=0,0
    while c%2==0:
        c//=2
        c2+=1
    while c%5==0:
        c//=5
        c5+=1
    if c2>=5 or c5>=5:
        continue
    for i in range(c2,4):
        for j in range(c5,4):
            ans+=num_num[i][j]


for a1 in twoP:
    if a1.numerator%5!=0:
        continue
    for a2 in fiveP:
        if a1.numerator%a2.denominator==0 and a2.numerator%a1.denominator==0:
            ans+=1


print(ans)
# print(num)
# print(twoP)
# print(fiveP)
# print(e)

Submission status: Runtime Error

Solution code:
from decimal import *

getcontext().prec = 20

N = int(input())
A = [int(Decimal(input())*(10**9)) for _ in [0]*N]

cnt = [[0]*20 for _ in [0]*20]
B = [None]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (i,j)
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Runtime Error

Solution code:
from fractions import Fraction

n=int(input())

num=[]
twoP=[]
fiveP=[]
e=[]

num_num=[[0 for i in range(5)]for j in range(5)]
two_num=[0 for i in range(50)]
five_num=[0 for i in range(50)]


for i in range(n):
    s=input()
    if "." in s: 
        b=len(s.split(".")[1])
    else:
        b=0
    s=int(s.replace(".",""))
    a=Fraction(s,10**b)

    if a.denominator==1:
        num.append(a)
        c=a.numerator
        two=0
        five=0
        while c%2==0:
            c//=2
            two+=1
        while c%5==0:
            c//=5
            five+=1

        num_num[two][five]+=1
        two_num[two]+=1
        five_num[five]+=1
    elif a.denominator%2==0 and a.denominator%5==0:
        e.append(a)
    elif a.denominator%5==0:
        fiveP.append(a)
        c=a.numerator
        two=0
        # while c%2==0:
        #     c//=2
        #     two+=1
        # two_num[two]+=1

    else:
        twoP.append(a)
        c=a.numerator
        five=0
        # while c%5==0:
        #     c//=5
        #     five+=1
        # five_num[five]+=1
ans= len(num)*(len(num)-1)//2
# print(ans)
for a in twoP:
    c=a.denominator
    count=0
    while c%2==0:
        count+=1
        c//=2
    # print(count,c)
    if count>=50:
        continue
    for i in range(count,50):
        ans+=two_num[i]
# print(ans)
for a in fiveP:
    c=a.denominator
    count=0
    while c%5==0:
        count+=1
        c//=5
    if count>=49:
        continue
    for i in range(count,50):
        ans +=five_num[i]
# print(ans)
for a in e:
    c=a.denominator
    c2,c5=0,0
    while c%2==0:
        c//=2
        c2+=1
    while c%5==0:
        c//=5
        c5+=1
    if c2>=5 or c5>=5:
        continue
    for i in range(c2,4):
        for j in range(c5,4):
            ans+=num_num[i][j]


for a1 in twoP:
    if a1.numerator%5!=0:
        continue
    for a2 in fiveP:
        if a1.numerator%a2.denominator==0 and a2.numerator%a1.denominator==0:
            ans+=1


print(ans)
# print(num)
# print(twoP)
# print(fiveP)
# print(e)

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 = [0]*N
for i in range(N):
  a = '{:.9f}'.format(float(input()))
  A[i] = int(a[:-10]+a[-9:])

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

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(26):
  dp[26][25-i] = dp[26][25-i] + dp[26][25-i]
  dp[25-i][26] = dp[25-i][26] + dp[25-i][26]
  
for i in range(26):
  for j in range(26):
    dp[25-i][25-j] = dp[25-i][25-j]+ dp[25-i][26-j] + dp[26-i][25-j] - dp[26-i][26-j]

#for t in ta:
#  print(t)
#for d in dp:
#  print(d)
  
ans = 0
for i in range(27):
  for j in range(27):
    #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:

from decimal import *

getcontext().prec = 20

N = int(input())
A = [int(Decimal(input())*(10**9)) for _ in [0]*N]

cnt = [[0]*20 for _ in [0]*20]
B = [None]*N
for k,a in enumerate(A):
    i = 0
    j = 0
    while a%2==0:
        a//=2
        i+=1
    while a%5==0:
        a//=5
        j+=1
    B[k] = (i,j)
    cnt[i][j] += 1

for i in range(1,20):
    i = 19-i
    for j in range(20):
        j = 19-j
        cnt[i][j] += cnt[i+1][j]

for i in range(20):
    i = 19-i
    for j in range(1,20):
        j = 19-j
        cnt[i][j] += cnt[i][j+1]

ans = 0
for i,j in B:
    me = int(i>=9 and j>=9)
    print(i,j,cnt[18-i][18-j]-me)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
readline = input

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

from fractions import Fraction

@mt
def slv(N, A):
    d = defaultdict(Counter)
    d5 = defaultdict(Counter)
    de = defaultdict(Counter)
    nd = Counter()
    for a in A:
        a += '.0'
        t = a.split('.')
        b = int(t[0]) * 10**9 + int(t[1]) * 10**(9- len(t[1]))
        e = str(b)
        for i in range(100):
            if e[-(i+1)] != '0':
                break

        d[i][b] += 1
        if e[-(i+1)] == '5':
            d5[i][b] += 1
        elif int(e[-(i+1)]) % 2 == 0:
            de[i][b] += 1
        nd[i] += 1

    ans = 0
    rk = sorted(d.keys(), reverse=True)
    for k, kk in combinations(rk, r=2):
        nk = nd[k]
        nkk = nd[kk]
        if k + kk >= 18:
            ans += nk * nkk
        elif k + kk > 10:
            for av, an in d5[k].items():
                for bv, bn in de[kk].items():
                    if (av * bv) % 10**18 == 0:
                        ans += an * bn
            for av, an in de[k].items():
                for bv, bn in d5[kk].items():
                    if (av * bv) % 10**18 == 0:
                        ans += an * bn
    for k in rk:
        nk = nd[k]
        if 2*k >= 18:
            ans += nk * (nk-1) // 2
        elif k + kk > 10:
            for av, an in d5[k].items():
                for bv, bn in de[k].items():
                    if (av * bv) % 10**18 == 0:
                        ans += an * bn
    return ans


def ref(N, A):
    B = []
    for a in A:
        t = a.split('.')
        b = 0
        if len(t) == 1:
            b = int(t[0]) * 10**9
        else:
            b = int(t[0]) * 10**9 + int(t[1]) * 10**(9 - len(t[1]))
        B.append(b)

    ans = 0
    for a, b in combinations(B, r=2):
        if (a * b ) % 10**18 == 0:
            print(a, b)
            ans += 1
    return ans

def main():
    N = read_int()
    A = [input() for _ in range(N)]
    print(slv(N, A))
    # print(ref(N, A))

    # N = 2 * 10**5
    # for _ in range(1000):
    #     A = []
    #     for _ in range(N):
    #         b = str(random.randint(1, 10)) + '.' + str(random.randint(0, 10**9))
    #         A.append(b)

    #     a = slv(N, A)
    #     # b = ref(N, A)
    #     # print(a, b)
    #     # if a != b:
    #     #     print(a, b)
    #     #     print(A)
    #     #     break



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = [0] * N
floatans=0
for i in range(len(B)):
    b_int, b_frac = str(A[i]).split(".")
    if len(b_frac)>4 and A[i].is_integer()==False:
        continue
    for j in range(i+1,len(B)):
        c_int, c_frac = str(A[j]).split(".")
        if A[i].is_integer()==False and (len(c_frac)>4 or len(b_int)<len(c_frac)):
            continue
        if (round(A[i]*(10**4))*round(A[j]*(10**4)))%(10**8)==0:
            floatans+=1
print(floatans)

Submission status: Runtime Error

Solution code:
import numpy as np
def main():
  n=int(input())
  a=[]
  b=[]
  c=[]
  z=0
  for i in range(n):
    tempa=input().split(".")
    if(len(tempa)==1):
      z=z+1
      tempa=int(tempa[0])
      if (tempa % 2) == 0  or (tempa % 5) == 0:
        a.append(int(tempa))
    else:
      ta=int(tempa[1])
      if ta==0:
        z=z+1
        tempa=int(tempa[0])
        if (tempa % 2) == 0  or (tempa % 5) == 0:
          a.append(int(tempa))
      else:
        b.append(int("".join(tempa)))
        c.append(10**len(tempa[1]))
  nz=n-z
  r=n*(n-1)//2
  fz=nz*z
  a=np.array(a)
  b=np.array(b)
  c=np.array(c)
  oab=np.outer(a,b)
  fz=fz-np.count_nonzero(oab%c==0)
  for j in range(nz-1):
    for k in range(j+1,nz):
      tempb=b[j]*b[k]
      tempc=c[j]*c[k]
      if (tempb % tempc) >0:
        fz=fz+1
  print(r-fz)
main()