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

Solution code:
import copy
import math
import time
import statistics
import math
from decimal import Decimal
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_DOWN

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''



def main():
    start = time.time()

    n = get_int()
    #youso2 = []
    #youso5 = []
    youso = []
    aite = [[0] * 20 for i in range(20)]

    ans = 0
    for i in range(0,n):
        s = input()
        wk = Decimal(s)
        wk = wk - wk.quantize(Decimal('0'), rounding=ROUND_DOWN)
        seisu = Decimal.is_zero(wk)

        if seisu:
            if '.' in s:
                s_i, s_d = s.split('.')
                s = s_i

            count2 = 0
            wk = int(s)
            for ii in range(0, 9):
                if wk % 2 == 0:
                    count2 += 1
                    wk = wk // 2
                else:
                    break

            count5 = 0
            wk = int(s)
            for ii in range(0, 6):
                if wk % 5 == 0:
                    count5 += 1
                    wk = wk // 5
                else:
                    break

            #youso.append([count2, count5])

        else:
            s_i, s_d = s.split('.')

            while s_d[-1] == '0':
                s_d = s_d[:-1]

            count2 = 0
            wk = int(s_i + s_d)
            for ii in range(0, 9):
                if (wk * 2) % 10 == 0:
                    wk = wk * 2 / 10
                    count2 += 1
                else:
                    break

            count5 = 0
            wk = int(s_d)
            for ii in range(0,9):
                if (wk * 5) % 10 == 0:
                    wk = wk * 5 / 10
                    count5 += 1
                else:
                    break

            count2_wk = -len(s_d) + count5
            count5 = -len(s_d) + count2
            count2 = count2_wk
            #youso.append([-len(s_d) + count5, -len(s_d) + count2])

        youso.append([count2, count5])
        aite[10 - count2][10 - count5] += 1
        #for ii in range (10 - count2, 20):
        #    for iii in range(10 - count5, 20):
        #        aite[ii][iii] += 1


    #print(time.time() - start)

    aite2 = [[0] * 20 for i in range(20)]
    for i in range (0,20):
        for ii in range (0, 20):
            for iii in range(i, 20):
                for iiii in range(ii, 20):
                    aite2[iii][iiii] += aite[i][ii]

    #print(time.time() - start)
    #print(youso)

    #for i in range(len(aite2)):
    #    print(i, aite2[i])

    ans = 0
    for i in range(0,n):
        y1 = youso[i]
        if y1[0] >= 0 and y1[1] >= 0:
            ans += aite2[10 + y1[0]][10 + y1[1]] -1
        else:
            ans += aite2[10 + y1[0]][10 + y1[1]]

    ans = ans // 2

    print(ans)
    #print(time.time() - start)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
debug=False
import random
from collections import Counter
from collections import defaultdict
from itertools import combinations
def fact(n):
    k5 = 0
    while n%5==0:
        n//=5
        k5+=1
    k2=0
    while n%2==0:
        n//=2
        k2+=1
    return (k2, k5)

n=5*10**4 if debug else int(input())
a=[]
aa=[]
inp = [] if not debug else [str(random.random()*10**4) for _ in range(n)]
if not debug:
    for _ in range(n):
        inp.append(input())
    
for i in range(n):
    n=inp[i]
    aa.append(n)
    if "." in n:
        p,q=n.split(".")
        a.append((int(p+q),len(q)))
    else:
        p=int(n)
        q=0
        a.append((p,0))
    
G=[]
for idx,v in enumerate(a):
    r2, r5 = fact(v[0])
    #print(r2,r5,v[1])
    G.append((r2-v[1], r5-v[1]))

H=Counter(G)

L = [(i,j) for i in range(-10,10) for j in range(-10,10)]

c=0
#print(H)
for l,m in combinations(L,2):
    if l[0]+m[0]>=0 and l[1]+m[1]>=0:
        k = H[l]*H[m]
        if k>0:
            #print(l,m,k)
            c+=k
            
for l in L:
    k = H[l]*(H[l]-1)//2
    if l[0]>=0 and l[1]>=0 and k>0:
        #print(l,l,k)
        c+=k
print(c)

Submission status: Wrong Answer

Solution code:
def divide(n, p):
    c = 0
    while (n%p == 0):
        c += 1
        n //= p
    c = min(c, 18)
    return c
    

n = int(input())
dp = [[0]*20 for _ in range(20)]
    
for i in range(n):
    s = float(input())
    s = int(s*1000000000)
    c1, c2 = divide(s, 2), divide(s, 5)
    dp[c1][c2] += 1
    
ans = 0
for i1 in range(20):
    for j1 in range(20):
        for i2 in range(20):
            for j2 in range(20):
                if i1+i2 >= 18 and j1+j2 >= 18:
                    if i1 == i2 and j1 == j2:
                        ans += dp[i1][j1]*(dp[i1][j1]-1)
                    else:
                        ans += dp[i1][j1]*dp[i2][j2]
            
        
print(ans//2)

Submission status: Wrong Answer

Solution code:
debug=False
import random
from collections import Counter
from collections import defaultdict
from itertools import combinations
def fact(n):
    k5 = 0
    while n%5==0:
        n//=5
        k5+=1
    k2=0
    while n%2==0:
        n//=2
        k2+=1
    return (k2, k5)

n=5*10**4 if debug else int(input())
a=[]
aa=[]
inp = [] if not debug else [str(random.random()*10**4) for _ in range(n)]
if not debug:
    for _ in range(n):
        inp.append(input())
    
for i in range(n):
    n=inp[i]
    aa.append(n)
    if "." in n:
        p,q=n.split(".")
        a.append((int(p+q),len(q)))
    else:
        p=int(n)
        q=0
        a.append((p,0))
    
G=[]
for idx,v in enumerate(a):
    r2, r5 = fact(v[0])
    #print(r2,r5,v[1])
    G.append((r2-v[1], r5-v[1]))

H=Counter(G)

L = [(i,j) for i in range(-10,10) for j in range(-10,10)]

c=0
#print(H)
for l,m in combinations(L,2):
    if l[0]+m[0]>=0 and l[1]+m[1]>=0:
        k = H[l]*H[m]
        if k>0:
            #print(l,m,k)
            c+=k
            
for l in L:
    k = H[l]*(H[l]-1)//2
    if l[0]+l[1]>=0 and m[0]+m[1]>=0 and k>0:
        #print(l,l,k)
        c+=k
print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[[0]*51 for _ in range(51)]
for _ in range(n):
    a=float(input())
    a*=10**9
    a=int(a)
    cnt2,cnt5=0,0
    while a%2==0:
        a//=2
        cnt2+=1
    while a%5==0:
        a//=5
        cnt5+=1
    p[cnt2][cnt5]+=1
ans=0
for i in range(51):
    for j in range(51):
        for k in range(51):
            for l in range(51):
                if k>=18-i and l>=18-j:
                    if i==k and j==l:
                        ans+=p[i][j]*(p[i][j]-1)
                    else:
                        ans+=p[i][j]*p[k][l]
print(ans//2)

Submission status: Wrong Answer

Solution code:
def divide(n, p):
    c = 0
    while (n%p == 0):
        c += 1
        n //= p
    c = min(c, 18)
    return c
    

def main():
    n = int(input())
    dp = [[0]*20 for _ in range(20)]
    
    for i in range(n):
        s = float(input())
        s = int(s*1000000000)
        c1, c2 = divide(s, 2), divide(s, 5)
        dp[c1][c2] += 1
        
    ans = 0
    for i1 in range(20):
        for j1 in range(20):
            for i2 in range(20):
                for j2 in range(20):
                    if i1+i2 >= 18 and j1+j2 >= 18:
                        if i1 == i2 and j1 == j2:
                            ans += dp[i1][j1]*(dp[i1][j1]-1)
                        else:
                            ans += dp[i1][j1]*dp[i2][j2]
            
        
    print(ans//2)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def divide(n, p):
    c = 0
    while (n%p == 0):
        c += 1
        n //= p
    c = min(c, 18)
    return c
    

def main():
    n = int(input())
    dp = [[0]*20 for _ in range(20)]
    
    for i in range(n):
        s = int(1e9*float(input()))
        c1, c2 = divide(s, 2), divide(s, 5)
        dp[c1][c2] += 1
        
    ans = 0
    for i1 in range(20):
        for j1 in range(20):
            for i2 in range(20):
                for j2 in range(20):
                    if i1+i2 >= 18 and j1+j2 >= 18:
                        if i1 == i2 and j1 == j2:
                            ans += dp[i1][j1]*(dp[i1][j1]-1)
                        else:
                            ans += dp[i1][j1]*dp[i2][j2]
            
        
    print(ans//2)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    c1, c2 = min(18, c1), min(18, c2)
    return (c1, c2)
    

def main():
    n = int(input())
    a = [None]*n
    for i in range(n):
        s = float(input())
        s *= 1e9
        s = int(s)
        a[i] = divide(s)

    dp = [[0]*20 for _ in range(20)]
    for i in range(n):
        c1, c2 = a[i]
        dp[c1][c2] += 1

    ans = 0
    for i1 in range(20):
        for j1 in range(20):
            for i2 in range(20):
                for j2 in range(20):
                    if i1+i2 >= 18 and j1+j2 >= 18:
                        if i1 == i2 and j1 == j2:
                            ans += dp[i1][j1]*(dp[i1][j1]-1)
                        else:
                            ans += dp[i1][j1]*dp[i2][j2]
            
        
    print(ans//2)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    c1, c2 = min(18, c1), min(18, c2)
    return (c1, c2)
    

def main():
    n = int(input())
    a = [None]*n
    for i in range(n):
        s = float(input())
        s *= 1e9
        s = int(s)
        a[i] = divide(s)

    dp = [[0]*20 for _ in range(20)]
    for i in range(n):
        c1, c2 = a[i]
        dp[c1][c2] += 1

    ans = 0
    for i1 in range(20):
        for j1 in range(20):
            for i2 in range(20):
                for j2 in range(20):
                    if i1+i2 >= 18 and j1+j2 >= 18:
                        if i1 == i2 and j1 == j2:
                            ans += dp[i1][j1]*(dp[i1][j1]-1)
                        else:
                            ans += dp[i1][j1]*dp[i2][j2]
            
        
    print(ans//2)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    c1, c2 = min(18, c1), min(18, c2)
    return (c1, c2)
    

def main():
    n = int(input())
    a = [divide(int(float(input())*10**9)) for _ in range(n)]

    dp = [[0]*20 for _ in range(20)]
    for i in range(n):
        c1, c2 = a[i]
        dp[c1][c2] += 1

    ans = 0
    for i1 in range(20):
        for j1 in range(20):
            for i2 in range(20):
                for j2 in range(20):
                    if i1+i2 >= 18 and j1+j2 >= 18:
                        if i1 == i2 and j1 == j2:
                            ans += dp[i1][j1]*(dp[i1][j1]-1)
                        else:
                            ans += dp[i1][j1]*dp[i2][j2]
            
        
    print(ans//2)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy
import math
import time
import statistics
import math
from decimal import Decimal
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN, ROUND_DOWN

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''



def main():
    start = time.time()

    n = get_int()
    #youso2 = []
    #youso5 = []
    youso = []
    aite = [[0] * 20 for i in range(20)]

    ans = 0
    for i in range(0,n):
        s = input()
        wk = Decimal(s)
        wk = wk - wk.quantize(Decimal('0'), rounding=ROUND_DOWN)
        seisu = Decimal.is_zero(wk)

        if seisu:
            if '.' in s:
                s_i, s_d = s.split('.')
                s = s_i

            count2 = 0
            wk = int(s)
            for ii in range(0, 9):
                if wk % 2 == 0:
                    count2 += 1
                    wk = wk // 2
                else:
                    break

            count5 = 0
            wk = int(s)
            for ii in range(0, 6):
                if wk % 5 == 0:
                    count5 += 1
                    wk = wk // 5
                else:
                    break

            #youso.append([count2, count5])

        else:
            s_i, s_d = s.split('.')

            count2 = 0
            wk = int(s_i + s_d)
            for ii in range(0, 9):
                if (wk * 2) % 10 == 0:
                    wk = wk * 2 / 10
                    count2 += 1
                else:
                    break

            count5 = 0
            wk = int(s_d)
            for ii in range(0,9):
                if (wk * 5) % 10 == 0:
                    wk = wk * 5 / 10
                    count5 += 1
                else:
                    break

            count2_wk = -len(s_d) + count5
            count5 = -len(s_d) + count2
            count2 = count2_wk
            #youso.append([-len(s_d) + count5, -len(s_d) + count2])

        youso.append([count2, count5])
        aite[10 - count2][10 - count5] += 1
        #for ii in range (10 - count2, 20):
        #    for iii in range(10 - count5, 20):
        #        aite[ii][iii] += 1


    #print(time.time() - start)

    aite2 = [[0] * 20 for i in range(20)]
    for i in range (0,20):
        for ii in range (0, 20):
            for iii in range(i, 20):
                for iiii in range(ii, 20):
                    aite2[iii][iiii] += aite[i][ii]

    #print(time.time() - start)
    #print(youso)

    #for i in range(len(aite2)):
    #    print(i, aite2[i])

    ans = 0
    for i in range(0,n):
        y1 = youso[i]
        if y1[0] >= 0 and y1[1] >= 0:
            ans += aite2[10 + y1[0]][10 + y1[1]] -1
        else:
            ans += aite2[10 + y1[0]][10 + y1[1]]

    ans = ans // 2

    print(ans)
    #print(time.time() - start)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    c1, c2 = min(18, c1), min(18, c2)
    return (c1, c2)
    

def main():
    n = int(input())
    a = [divide(int(float(input())*10**9)) for _ in range(n)]

    dp = [[0]*20 for _ in range(20)]
    for i in range(n):
        c1, c2 = a[i]
        dp[c1][c2] += 1
    
    for i in range(18, -1, -1):
        for j in range(18, -1, -1):
            dp[i][j] += dp[i+1][j]+dp[i][j+1]-dp[i+1][j+1]

    ans = 0
    for i in range(n):
        c1, c2 = a[i]
        if (c1 >= 9 and c2 >= 9):
            ans -= 1
        ans += dp[18-c1][18-c2]
        
    print(ans//2)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
M = 10
L = 2*M
A = [[0 for _ in range(L+1)] for _ in range(L+1)]

for _ in range(N):
  y = float(input())
  x = y
  x *= 10.**M
  x = int(x)
  k_2 = 0
  while x % 2 == 0 and k_2 < 2*M:
    x = x // 2
    k_2 += 1
  k_5 = 0 
  while x % 5 == 0 and k_5 < 2*M:
    x = x // 5
    k_5 += 1
  A[k_2][k_5] += 1

ans = 0
for k_2 in range(L+1):
  for k_5 in range(L+1):
    for l_2 in range(k_2, L+1):
      for l_5 in range(L+1):
        if k_2+l_2 >= 2*M and k_5+l_5 >= 2*M:
          if k_2 == l_2 and k_5 == l_5:
            ans += A[k_2][k_5]*(A[k_2][k_5]-1)//2
          elif l_2 > k_2 or (k_2 == l_2 and k_5 < l_5):
            ans += A[k_2][k_5]*A[l_2][l_5]          
#print(A)
print(ans)

Submission status: Wrong Answer

Solution code:
print(246)
c = 0
for i in range(1, 10):
    c += 4
    print("<", 10+i, 0, 20+i)
    print("+", 10+i, 20+i, 10+i+1)
    print("<", 30+i, 1, 40+i)
    print("+", 30+i, 40+i, 30+i+1)
for i in range(10, 0, -1):
    print("<", 30+i, 30+1, 30+i)
    c+=1

for i in range(10):
    for j in range(10):
        c+=2
        print("<", 30+i+1, 10+i+1, 100+10*i+10*j)
        print("+", 2, 100+10*i+10*j, 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
    a = float(input())*10**4
    if a.is_integer():
        A.append(a)

ans = 0

for i in range(len(A)):
    for j in range(i):
        F = (A[i]*A[j])/10**8
        if float(F).is_integer():
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    c1, c2 = min(18, c1), min(18, c2)
    return (c1, c2)
    

def main():
    n = int(input())
    a = [divide(int(float(input())*1e9)) for _ in range(n)]

    dp = [[0]*20 for _ in range(20)]
    ans = 0
    for i in range(n):
        c1, c2 = a[i]
        ans += dp[18-c1][18-c2]
        for j in range(c1+1):
            for k in range(c2+1):
                dp[j][k] += 1
        
    print(ans)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0]*N
B = [[0]*19 for x in range(19)]
C = [0]*N
D = [0]*N
a,b,c,d,e,ans = 0,['0']*9,0,0,0,0
for i in range(N):
    c = (input()+'.0').split('.')
    b = ['0']*9
    for k,v in enumerate(c[1]):
        b[k] = v
    A[i] = int(c[0]+''.join(b))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from decimal import Decimal
N = int(input())
T = defaultdict(int)
a = 0
b = 0
for i in range(N):
    A = Decimal((input()))
    A *= 10**9
    A = int(A)
    t = 0
    f = 0
    while(True):
        if A % 2 != 0:
            break
        A = A // 2
        t += 1
    while (True):
        if A % 5 != 0:
            break
        A = A // 5
        f += 1
    T[(t, f)] += 1
    a = max(a, t)
    b = max(b, f)

print(T)
ans = 0
for k, v in T.items():
    for i in range(18-k[0], a+1):
        for j in range(18-k[1], b+1):
            if (i, j) in T:
                if k[0] == i and k[1] == j:
                    ans += v * (v-1)
                else:
                    ans += v * T[(i, j)]
print(ans//2)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
A2 = []
A5 = []
for i in range(N):
    a=input()
    tmp = int(a.replace('.', ''))
    count2 = 0
    count5 = 0
    for _ in range(18):
        if tmp % 2 == 0:
            count2 += 1
            tmp /= 2
        else:
            break
    for _ in range(18):
        if tmp % 5 == 0:
            count5 += 1
            tmp /= 5
        else:
            break
    if a.find('.') > 0:
        count2 += 10 - len(a) + a.find('.')
        count5 += 10 - len(a) + a.find('.')
    else:
        count2 += 9
        count5 += 9
    A2.append(count2)
    A5.append(count5)
ans=0
for i in range(N):
    for j in range(i+1,N):
        if A2[i] + A2[j] >= 18 and A5[i] + A5[j] >= 18:
            ans += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def five(x):
    cnt1 = 0
    while x%5==0:
        cnt1+= 1
        x = x//5
    cnt2 = 0
    while x%2==0:
        cnt2+= 1
        x = x//2
    return (cnt1, cnt2)

N = int(input())

F = []
for i in range(N):
    A = float(input())
    A = round(A*(10**9))
    F.append(five(A))

F.sort()
# print(F)
j = 0
temp = 0
dp = [0]*19
k = 0
for i in range(N):
    if N-1-j < i:
        dp[min(F[i][1], 18)] -= 1
        # print(i, N - j - 1, dp)
    while N-1-j> i and F[i][0]+F[N-1-j][0] >= 18:
        dp[min(F[N-1-j][1],18)] += 1
        # print(i, N - j - 1, dp)
        j += 1
    k = sum(dp[:18-F[i][1]])
    temp += min(j, N-i-1) - k
    # print(j, N-i-1, k, temp)

print(temp)

"""
5
1
1
1
1
1
"""

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
    a = float(input())*10**9
    A.append(a)

ans = 0

for i in range(N):
    for j in range(i):
        F = (A[i]*A[j])/10**18
        if float(F).is_integer():
            ans += 1

print(ans)

Submission status: Wrong Answer

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
    return ans

n=int(input())
a=[float(input()) for _ in range(n)]
b=[prime(a[i]) for i in range(n)]
ans=0

d=[[0 for k in range(19)] for l in range(19)]

for i in range(len(b)):
    for k in range(19):
        for l in range(19):
            if b[i][0]>=k and b[i][1]>=l:
                d[l][k]+=1

for i in range(len(b)):
    ans+=d[max([0,-b[i][1]+18])][max([0,-b[i][0]+18])]
    if b[i][0]>=9 and b[i][1]>=9:
        ans-=1
print(ans//2)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def divide(n):
    c1, c2 = 0, 0
    while (n%2 == 0):
        c1 += 1
        n //= 2
    while (n%5 == 0):
        c2 += 1
        n //= 5
    c1, c2 = min(18, c1), min(18, c2)
    return (c1, c2)
    

def main():
    n = int(input())
    a = [divide(int(float(input())*1e9)) for _ in range(n)]

    dp = [[0]*20 for _ in range(20)]
    for i in range(n):
        c1, c2 = a[i]
        dp[c1][c2] += 1
    
    for i in range(18, -1, -1):
        for j in range(18, -1, -1):
            dp[i][j] += dp[i+1][j]+dp[i][j+1]-dp[i+1][j+1]

    ans = 0
    for i in range(n):
        c1, c2 = a[i]
        if (c1 >= 9 and c2 >= 9):
            ans -= 1
        ans += dp[18-c1][18-c2]
        
    print(ans//2)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
A_list = []
A_yakusu = []
cnt = 0

for i in range(0, N):
    a = float(input())
    A_list.append(a*10**9)

for i in range(0, N-1):
    for j in range(i+1, N):
        if A_list[i]*A_list[j] % (10**18) == 0:
            cnt += 1
            #print(i,j)
print(cnt)

Submission status: Wrong Answer

Solution code:
def five(x):
    cnt1 = 0
    while x%5==0:
        cnt1+= 1
        x = x//5
    cnt2 = 0
    while x%2==0:
        cnt2+= 1
        x = x//2
    return (cnt1, cnt2)

N = int(input())

F = []
for i in range(N):
    A = float(input())
    A = round(A*(10**9))
    F.append(five(A))

F.sort()
# print(F)
j = 0
temp = 0
dp = [0]*20
k = 0
for i in range(N-1):
    if N-1-j < i:
        dp[min(F[i][1], 18)] -= 1
        # print(i, N - j - 1, dp)
    while N-1-j> i and F[i][0]+F[N-1-j][0] >= 18:
        dp[min(F[N-1-j][1],18)] += 1
        # rint(i, N - j - 1, dp)
        j += 1
    k = sum(dp[:19-F[i][1]])
    temp += min(j, N-i-1) - k
    # print(j, N-i-1, k, temp)

print(temp)

"""
5
1
1
1
1
1
"""

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
T = defaultdict(int)
a = 0
b = 0
for i in range(N):
    A = float(input())
    A *= 10**9
    A = int(A)
    t = 0
    f = 0
    while(True):
        if A % 2 != 0:
            break
        A = A // 2
        t += 1
    while (True):
        if A % 5 != 0:
            break
        A = A // 5
        f += 1
    T[(t, f)] += 1
    a = max(a, t)
    b = max(b, f)

ans = 0
for k, v in T.items():
    for i in range(18-k[0], a+1):
        for j in range(18-k[1], b+1):
            if (i, j) in T:
                if k[0] == i and k[1] == j:
                    ans += v * (v-1)
                else:
                    ans += v * T[(i, j)]
print(ans//2)

Submission status: Wrong Answer

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
    i = min(19,i)
    j = min(19,j)
    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)
    ans += cnt[max(0,18-i)][max(0,18-j)]-me

print(ans//2)

Submission status: Wrong Answer

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

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

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

def bonankai(p,q):
    return nankai(p,2)-nankai(q,2)+35,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)
        if res[1]==9:
            natu+=1
    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(69,-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(71):
        bo[i][q]+=bo[i][q+1]

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

Submission status: Wrong Answer

Solution code:
n=int(input())
# A=[]
excel=[[0]*20 for i in range(50)]
query=[]
for i in range(n):
    q=float(input())
    q*=10**9
    q=int(q)
    num2=0 ;num5=0
    k=q
    for i in range(50):
        if k%2==0:
            k//=2
            num2+=1
        else:break
    k=q
    for i in range(20):
        if k%5==0:
            k//=5
            num5+=1
        else:break
    excel[num2][num5]+=1
    query.append([max(0,18-num2),max(0,18-num5)])

A=[[0] * 20 for i in range(50)] #累積和
for i in range(49,-1,-1):
    for j in range(19,-1,-1):
        if i==49 and j==19:
            A[i][j]=excel[i][j]
        elif i==49:
            A[i][j]=A[i][j+1]+excel[i][j]
        elif j==19:
            A[i][j]=A[i+1][j] + excel[i][j]
        else:
            A[i][j]=excel[i][j]+ A[i+1][j]+A[i][j+1]-A[i+1][j+1]

ans=0
for l in query:
    num2,num5=l
    if num2<=9 and num5<=9:
        ans+=A[num2][num5]-1
    else:
        ans+=A[num2][num5]

#for i in range(50):
 #   print(excel[:][i] , A[:][i])
print(ans//2)

Submission status: Wrong Answer

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

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

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

def bonankai(p,q):
    return nankai(p,2)-nankai(q,2)+35,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(69,-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(71):
        bo[i][q]+=bo[i][q+1]

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
twofive = defaultdict(int)
for i in range(N):
    a = float(input()) * (10**9)
    b = 0
    c = 0
    while a % 2 == 0 and b < 18:
        b += 1
        a //= 2
    while a % 5 == 0 and c < 18:
        c += 1
        a //= 5
    twofive[(b, c)] += 1
ans = 0
for b, c in twofive.keys():
    for d, e in twofive.keys():
        if b + d >= 18 and c + e >= 18:
            if (b, c) != (d, e):
                ans += twofive[(b, c)] * twofive[(d, e)]
            else:
                ans += twofive[(b, c)] * (twofive[(b, c)] - 1)
print(ans//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
# A=[]
excel=[[0]*20 for i in range(50)]
query=[]
for i in range(n):
    q=float(input())
    q*=10**9
    q=int(q)
    num2=0 ;num5=0
    k=q
    for i in range(50):
        if k%2==0:
            k//=2
            num2+=1
        else:break
    k=q
    for i in range(20):
        if k%5==0:
            k//=5
            num5+=1
        else:break
    excel[num2][num5]+=1
    query.append([18-num2,18-num5])

A=[[0] * 20 for i in range(50)] #累積和
for i in range(49,-1,-1):
    for j in range(19,-1,-1):
        if i==49 and j==19:
            A[i][j]=excel[i][j]
        elif i==49:
            A[i][j]=A[i][j+1]+excel[i][j]
        elif j==19:
            A[i][j]=A[i+1][j] + excel[i][j]
        else:
            A[i][j]=excel[i][j]+ A[i+1][j]+A[i][j+1]-A[i+1][j+1]

ans=0
for l in query:
    num2,num5=l
    if num2<=9 and num5<=9:
        ans+=A[num2][num5]-1
    else:
        ans+=A[num2][num5]

# for i in range(50):
#     print(excel[:][i] , A[:][i])
print(ans//2)