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:
N = int(input())
A = [float(input()) for i in range(N)]
#A = [len(input()) for i in range(N)]
count = 0
B = []
C = []
D = []

for i in range(N):
    if A[i] % 1 == 0:
        B.append(A[i])
    elif A[i] > 0.0001 and A[i] < 1 and A[i] * (10 ** 4) % 1 == 0:
        C.append(A[i])
    elif A[i] > 1 and A[i] * (10 ** 4) % 1 == 0:
        D.append(A[i])

for i in range(len(B)):
    count += i

for i in B:
    for j in C:
        if ((i * j * (10 ** 4)) % (1 * 10 ** 4) == 0):
            count += 1

for i in B:
    for j in D:
        if ((i * j * (10 ** 4)) % (1 * 10 ** 4) == 0):
            count += 1

for i in C:
    for j in D:
        if ((i * (10 ** 4)) * (j * (10 ** 4))) % (1 * (10 ** 4) ** 2)  == 0:
            count += 1

for i in range(len(D)):
    for j in range(i+1, len(D)):
        if ((D[i] * (10 ** 4)) * (D[j] * (10 ** 4))) % (1 * (10 ** 4) ** 2) == 0:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from decimal import Decimal
from collections import defaultdict

n = int(input())

integer_num = 0
dic = defaultdict(list)
li = []

# 約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors  

for _ in range(n):
    a = float(input())
    deci = Fraction(Decimal(str(a)))
    
    # 分母が10000より大きかった場合
    if deci.denominator >= 10**4:
        continue

    # 分母が1だった場合(整数の場合)
    if deci.denominator == 1:
        integer_num += 1
    
    dic[deci.denominator].append(deci.numerator)

    li.append((deci.numerator,deci.denominator))

point = 0

for i,j in li:
    div = make_divisors(i)
    for k in div:
        if k in dic:
            for l in dic[k]:
                if l%j == 0:
                    point += 1

print((point-integer_num)//2)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[]
re=0
for i in range(N):
  s=float(input())
  a.append(s)
for x in range(N-1):
  y=1
  while True:
    c=a[x+y]
    d=a[x]*c
    if d.is_integer():
      re+=1
    if c==a[-1]:
      break
    y+=1
print(re)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())

AS = [input().strip() for _ in range(N)]

nums = [int(a.replace('.', '')) for a in AS]
dens = [1 if '.' not in a else 10**(len(a) - a.index('.') - 1) for a in AS]

# print(nums, dens)

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    return gcd(b, a%b)

gs = [gcd(num, den) for num, den in zip(nums, dens)]
nums = [num // g for num, g in zip(nums, gs)]
dens = [den // g for den, g in zip(dens, gs)]

def signature(n):
    e2, e5 = 0, 0
    while n % 2 == 0:
        n //= 2
        e2 += 1
    while n % 5 == 0:
        n //= 2
        e5 += 1
    return (e2, e5)

lookup = defaultdict(int)
for num, den in zip(nums, dens):
    n2, n5 = signature(num)
    d2, d5 = signature(den)
    lookup[(n2-d2, n5-d5)]+=1

ans = 0
for k1 in lookup:
    for k2 in lookup:
        v1, v2 = lookup[k1], lookup[k2]
        x1, y1 = k1
        x2, y2 = k2
        if x1 + x2 >= 0 and y1 + y2 >=0:
            if k1 == k2:
                ans += v1*(v1-1)
            else:
                ans += v1*v2

ans //= 2
print(ans)

Submission status: Wrong Answer

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



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


n = I()
D = defaultdict(lambda:defaultdict(int))
for j in range(n):
    a = Decimal(input())
    cnt1 = 0
    cnt2 = 0
    while a % 1:
        a *= 10
        cnt1 -= 1
        cnt2 -= 1
    while a % 2 == 0:
        a /= 2
        cnt1 += 1
    while a % 5 == 0:
        a /= 5
        cnt2 += 1
    D[cnt1][cnt2] += 1

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

print(ans // 2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())

AS = [input().strip() for _ in range(N)]

nums = [int(a.replace('.', '')) for a in AS]
dens = [1 if '.' not in a else 10**(len(a) - a.index('.') - 1) for a in AS]

print(nums, dens)

def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    return gcd(b, a%b)

gs = [gcd(num, den) for num, den in zip(nums, dens)]
nums = [num // g for num, g in zip(nums, gs)]
dens = [den // g for den, g in zip(dens, gs)]

def signature(n):
    e2, e5 = 0, 0
    while n % 2 == 0:
        n //= 2
        e2 += 1
    while n % 5 == 0:
        n //= 2
        e5 += 1
    return (e2, e5)

lookup = defaultdict(int)
for num, den in zip(nums, dens):
    n2, n5 = signature(num)
    d2, d5 = signature(den)
    lookup[(n2-d2, n5-d5)]+=1

ans = 0
for k1 in lookup:
    for k2 in lookup:
        v1, v2 = lookup[k1], lookup[k2]
        x1, y1 = k1
        x2, y2 = k2
        if x1 + x2 >= 0 and y1 + y2 >=0:
            if k1 == k2:
                ans += v1*(v1-1)
            else:
                ans += v1*v2

ans //= 2
print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal, getcontext
getcontext().prec = 30

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 = Decimal(input())
    A = int(A*(10**9))
    F.append(five(A))
exit()

F.sort()
# print(F)
j = 0
temp = 0
dp = [0]*19
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
        # 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)

print(temp)

"""
3
0.1
0.1
10
"""

Submission status: Wrong Answer

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 c2-b, c5-b

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('.')
            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]*50 for _ in range(20)]
    # print(A2)
    # print(A5)
    # print(AS)
    for i in range(N):
        a, b = A5[i]+9, A2[i]+9
        R[a][b] += 1
    AR = [ [0]*50 for _ in range(20)]
    for i in range(19,-1,-1):
        for j in range(48,-1,-1):
            AR[i][j] = R[i][j] + AR[i][j+1]
    for j in range(50):
        for i in range(18,-1,-1):
            AR[i][j] += AR[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 += AR[-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: 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 = []

    ans = 0
    for i in range(0,n):
        s = input()

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

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

            youso.append([count2, count5])
            #youso2.append(count2)
            #youso5.append(count5)

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

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

            #youso2.append(-len(s_d) + count2)

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

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

    #print(time.time() - start)
    #print(youso2)
    #print(youso5)

    ans = 0
    for i in range(0,n):
        y1 = youso[i]
        for ii in range(i+1,n):
            y2 = youso[ii]

            if (y1[0] + y2[0] >= 0) and (y1[1] + y2[1] >= 0):
                ans += 1


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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    N=int(input())
    L=[]
    for i in range(N):
        s=input()
        if '.' not in s:
            n=int(s)
            m=0
        else:
            n=int(s.replace('.',''))
            m=len(s)-s.find('.')-1
            
        
        n2=n
        n5=n

        c2=0
        while n2%2==0:
            n2//=2
            c2+=1
        
        c5=0
        while n5%5==0:
            n5//=2
            c5+=1
        
        L.append((c2,c5,m))
    count=0
    for i in range(N):
        for j in range(i+1,N):
            tup1=L[i]
            tup2=L[j]
            if min(tup1[0]+tup2[0],tup1[1]+tup2[1])>=tup1[2]+tup2[2]:
                count+=1

    print(count)
main()

Submission status: Wrong Answer

Solution code:
from scipy.special import comb

n = int(input())
count = 0
a = []
b = []
for i in range(n):
  x = float(input())
  if x.is_integer():
    count = count + 1
    b.append(x)
  else:
    a.append(x)
#  整数×整数
sum = comb(count, 2, exact= True)

#  小数×整数
for i in range(len(a)):
  x = a[i]
  for j in range(len(b)):
    if (x * b[j]).is_integer():
      sum = sum + 1

# 小数×商数
for i in range(len(a)):
  for j in range(i+1, len(a)-1):
    if (a[i]* a[j]).is_integer():
      sum = sum + 1
print(sum)

Submission status: Wrong Answer

Solution code:
import re
import sys
import numpy as np
import copy
from collections import deque
input = sys.stdin.readline
np.set_printoptions(precision=9)


def print_ans(N, ar):
    """Test Case
    >>> print_ans(5,[7.5,2.4,17.000000001,17,16.000000000])
    3
    >>> print_ans(11,[0.9,1,1,1.25,2.30000,5,70,0.000000001,9999.999999999,0.999999999,1.000000001])
    8
    """
    ar = deque(ar)
    array = deque()
    array.append(np.array(ar, dtype='float64'))
    for i in range(N-1):
        tmp = ar.popleft()
        ar.append(tmp)
        array.append(np.array(ar, dtype='float64'))
    array = np.array(array)
    ans = 0
    for i in range(N-1):
        a1 = array[i, 0] * (10 ** 9)
        a2 = array[i, 1:N-i] * (10 ** 9)
        tmp_list = a1 * a2
        tmp_list = tmp_list / (10 ** 18)
        ans += np.count_nonzero(tmp_list == tmp_list.astype('int'))
    print(ans)


if __name__ == '__main__':
    N = int(input().rstrip())
    ar = [float(input().rstrip()) for _ in range(N)]
    print_ans(N, ar)

Submission status: Wrong Answer

Solution code:
n = int(input())
from itertools import combinations
L = []
for i in range(n):
    s = float(input())
    L.append(s)

cnt = 0
for v in combinations(L,2):
    #print(v[0]*v[1]%1 == 0 , int(v[0]*10**9)*int(v[1]*10**9) == v[0]*v[1]*10**18,v[0]*v[1])
    if v[0]*v[1]%1 == 0 and int(v[0]*10**9)*int(v[1]*10**9) == v[0]*v[1]*10**18 :
            
        cnt +=1
print(cnt)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal, getcontext
getcontext().prec = 30

def five(x):
    cnt = 0
    while x%5==0:
        cnt+= 1
        x = x//5
    return cnt

def two(x):
    cnt = 0
    while x%2==0:
        cnt+= 1
        x = x//2
    return cnt

N = int(input())

F = []
for i in range(N):
    A = Decimal(input())
    A = int(A*(10**9))
    F.append((five(A), two(A)))

exit()
F.sort()
# print(F)
j = 0
temp = 0
dp = [0]*19
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
        # 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)

print(temp)

"""
3
0.1
0.1
10
"""

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
ans=0
for i in range(n):
    a[i]=(float(input()))*1000000000.0
for i in range(n-1):
    for j in range(i+1,n):
        k=a[i]*a[j]/(10.0**18)
        if k.is_integer():
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:

from fractions import Fraction
from decimal import Decimal
n = int(input())
a = []
b = []
for i in range(0,n):
	c = float(input())
	a.append(c)
	d = str(a[i])
	f = Fraction(Decimal(d))
	b.append(f)

x = []
y = []
B = []
S = []

for i in range(0,n):
	x.append(b[i].numerator)
	y.append(b[i].denominator)
	if b[i] < 1:
		S.append(i)
	else:
		B.append(i)

count = 0

for i in B:
	for j in range(i+1,n):
		if (x[i]*x[j]) % (y[i]*y[j]) == 0:
			count += 1

for i in S:
	for j in B:
		if i > j:
			print('break')
		if (x[i]*x[j]) % (y[i]*y[j]) == 0:
			count += 1

print(count)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal, getcontext
getcontext().prec = 30

def five(x):
    cnt = 0
    while x%5==0:
        cnt+= 1
        x = x//5
    return cnt

def two(x):
    cnt = 0
    while x%2==0:
        cnt+= 1
        x = x//2
    return cnt

N = int(input())

F = []
for i in range(N):
    A = Decimal(input())
    A = int(A*(10**9))
    F.append((five(A), two(A)))

F.sort()
# print(F)
j = 0
temp = 0
dp = [0]*19
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
        # 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)

print(temp)

"""
3
0.1
0.1
10
"""

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from decimal import Decimal

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

c = {}
intc = 0
ints = []
decs = []
for d in A:
    if d in c:
        c[d] += 1
        if d == int(d):
            intc += 1
    else:
        c[d] = 1
        if d == int(d):
            intc += 1
            ints.append(d)
        else:
            decs.append(d)

result = intc * (intc - 1) // 2
for i in range(len(decs)):
    a = decs[i]
    ca = c[a]

    t = 1
    b = a - int(a)
    while True:
        b *= 10
        if b == int(b):
            p = t
            break
        t *= 10

    t = max(bisect_left(decs, 1 / a), i + 1)
    for j in range(t, len(decs)):
        b = decs[j]
        t = a * b
        if t == int(t):
            result += ca * c[b]

    t = bisect_left(ints, p)
    for j in range(t, len(ints)):
        b = ints[j]
        t = a * b
        if t == int(t):
            result += ca * c[b]

print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())

int_cnt = 0
int_25 = [[0 for _ in range(10)] for _ in range(10)]
float_25 = [[0 for _ in range(10)] for _ in range(10)]
float_2 = [[0 for _ in range(10)] for _ in range(10)]
float_5 = [[0 for _ in range(10)] for _ in range(10)]

for _ in range(n):
    a = float(input())
    if a % 1 == 0:
        int_cnt += 1
        t = 0
        while a % 2 == 0:
            a //= 2
            t += 1
        t = min(t, 9)
        f = 0
        while a % 5 == 0:
            a //= 5
            f += 1
        f = min(f, 9)
        int_25[t][f] += 1
    else:
        a *= 10 ** 9
        a = int(a)
        cnt = 9
        while a % 10 == 0:
            a //= 10
            cnt -= 1
        t = 0
        while a % 2 == 0:
            a //= 2
            t += 1
        f = 0
        while a % 5 == 0:
            a //= 5
            f += 1
        tt = min(t - cnt, 9)
        ff = min(f - cnt, 9)
        tt = max(tt, 0)
        tf = max(ff, 0)
        float_25[max(0, cnt - t)][max(0, cnt - f)] += 1
        float_2[tt][max(0, cnt - f)] += 1
        float_5[max(0, cnt - t)][ff] += 1


ans = int_cnt * (int_cnt - 1) // 2
for i in range(10):
    for j in range(10):
        for k in range(i + 1):
            for l in range(j + 1):
                ans += int_25[i][j] * float_25[k][l]

for i in range(10):
    for j in range(10):
        for k in range(10):
            for l in range(10):
                if (i - j > 0) and (k - l > 0):
                    ans += float_2[i][l] * float_5[j][k]
    
print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal, getcontext
getcontext().prec = 30

def five(x):
    cnt = 0
    while x%5==0:
        cnt+= 1
        x = x//5
    return cnt

def two(x):
    cnt = 0
    while x%2==0:
        cnt+= 1
        x = x//2
    return cnt

N = int(input())

F = []
for i in range(N):
    A = Decimal(input())
    A = int(A*(10**9))
    F.append((five(A), two(A)))

F.sort()
# print(F)
j = 0
temp = 0
dp = [0]*19
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
        # 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)

print(temp)

"""
3
0.1
0.1
10
"""

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
l = []
for i in range(n):
    a = str(input())
    if "." not in a:
        l.append(float(a))
    else:
        dot = a.index(".")
        if len(a)-dot-1 <= 4:
            l.append(float(a))
        else:
            flag = 1
            for j in range(dot+5,len(a)):
                if a[j] != "0":
                    flag = 0
            if flag: l.append(float(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 and t != 0:
        t //= 2
        memo[i][0] += 1
    while t%5 == 0 and t != 0:
        t //= 5
        memo[i][1] += 1
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:
        if memo[i][0] > 8:
            memo[i][0] = 8
        if memo[i][1] > 8:
            memo[i][1] = 8
        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]
"""
for l in mem2:
    print(l)
print("!")
for l in mems:
    print(l)
"""
s = 0
for i in range(9):
    for j in range(9):
        #print(i,j,mem2[i][j],mems[8-i][8-j])
        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: Wrong Answer

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

b = []
for i in range(n):
    s = str(a[i])
    t = s.split(".")
    if len(t) == 2:
        if len(t[1]) >= 5:
            pass
        else:
            b.append(a[i])
    else:
        b.append(a[i])

ans = 0
for i in range(len(b)):
    for j in range(i+1,len(b)):
        temp = int(b[i]*10**4) * int(b[j]*10**4)
        if (temp % 10**8 == 0):
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
from decimal import Decimal

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

c = {}
intc = 0
ints = []
decs = []
for d in A:
    if d in c:
        c[d] += 1
        if d == int(d):
            intc += 1
    else:
        c[d] = 1
        if d == int(d):
            intc += 1
            ints.append(d)
        else:
            decs.append(d)

result = intc * (intc - 1) // 2
for i in range(len(decs)):
    a = decs[i]
    ca = c[a]

    t = 1
    b = a - int(a)
    while True:
        b *= 10
        if b == int(b):
            p = t
            break
        t *= 10

    t = max(bisect_left(decs, p), i + 1)
    for j in range(t, len(decs)):
        b = decs[j]
        t = a * b
        if t == int(t):
            result += ca * c[b]

    t = bisect_left(ints, p)
    for j in range(t, len(ints)):
        b = ints[j]
        t = a * b
        if t == int(t):
            result += ca * c[b]

print(result)

Submission status: Wrong Answer

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):
        kakeru = a[i]*a[j]
        if i < j:
            if kakeru - int(kakeru) == 0:
                count += 1
                print(a[i])
                print(a[j])

print(count)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
#整数と整数
#有限整数は、「2^t × 5^f」で表せる。
#A = sys.stdin.readlines()
MN = [[0 for i in range(35)] for j in range(35)]
#MN[i][j] = プラスi-9,マイナスi-9
for _ in range(N):
    a = input()
    two = 0
    five = 0
    ten = 0
    if "." in a:
        shosuten = a.index(".")
        ten = len(a) - shosuten - 1
        a = int("".join([hoge for hoge in a if hoge != "."]))
        two = ten
        five = ten
    else:
        a = int(a)
        two = 0
        five = 0  
    while a%5 == 0:
        a //= 5
        five -= 1
    while a%2 == 0:
        a //= 2
        two -= 1
    MN[two+5][five+5] += 1
    

ans = 0
selfu = 0
for two1 in range(35):
    for two2 in range(35):
        if two1 + two2 > 10:
            break
        for five1 in range(35):
            for five2 in range(35):
                abe = MN[two1][five1]
                nana = MN[two2][five2]
                if two1 + two2 <=10 and five1 + five2 <= 10:
                    if two1 == two2 and five1 == five2:
                        if abe:
                            ans += abe*(nana-1)
                    else:
                        ans += abe*nana
print(ans//2)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
from decimal import Decimal
from collections import defaultdict

n = int(input())

integer_num = 0
dic = defaultdict(list)
li = []

# 約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors  

for _ in range(n):
    a = float(input())
    deci = Fraction(Decimal(str(a)))
    
    # 分母が10000より大きかった場合
    if deci.denominator >= 10**4:
        continue

    # 分母が1だった場合(整数の場合)
    if deci.denominator == 1:
        integer_num += 1
    
    dic[deci.denominator].append(deci.numerator)

    li.append((deci.numerator,deci.denominator))

point = 0

for i,j in li:
    div = make_divisors(i)
    for k in div:
        if k in dic:
            for l in dic[k]:
                if l%j == 0:
                    point += 1

print(point//2-integer_num//2)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
class Bit:
    def __init__(self, lst):
        t = 1
        while (t << 1) <= len(lst):
            for i in range(t, len(lst) - t + 1, t << 1):
                lst[i + t - 1] += lst[i - 1]
            t <<= 1
        self.lst = lst

    def add(self, pos, value):
        pos += 1
        while pos <= len(self.lst):
            self.lst[pos - 1] += value
            pos += pos & (-pos)

    def update(self, pos, value):
        diff = value - self.at(pos)
        self.add(pos, diff)

    def at(self, pos):
        return self.sum(pos + 1) - self.sum(pos)
    
    def sum(self, pos):
        # sum of [0, pos)
        if pos == 0:
            return 0
        s = 0
        while pos > 0:
            s += self.lst[pos - 1]
            #pos -= pos & (-pos)
            pos &= ~(-pos)
        return s
    
def solve():
    N = int(readline())
    A = [float(readline()) for i in range(N)]

    C = [0] * N
    c5s = set()

    for i, a in enumerate(A):
        b = a * (10 ** 10)
        c2, c5 = -10, -10
        while b % 2 == 0:
            b //= 2
            c2 += 1
        
        while b % 5 == 0:
            b //= 5
            c5 += 1
        
        C[i] = (c2, c5)
        c5s.add(c5)
        c5s.add(-c5)

    c5_to_i = {c5: i for i, c5 in enumerate(sorted(c5s))}
    
    C.sort()

    c5_comp = [c5_to_i[c5] for c2, c5 in C]
    
    bit = Bit([0] * len(c5_to_i))

    c5_max = max(c5 for c2, c5 in C)


    ans = 0
    j = N - 1
    for i, (c2, c5) in enumerate(C):
        if c2 < 0:
            l, r = i, N
            while l + 1 < r:
                m = (l + r) // 2
                if C[m][0] + c2 >= 0:
                    r = m
                else:
                    l = m
            if r == N:
                continue
            
            while j >= r:
                bit.add(c5_comp[j], 1)
                j -= 1
            
            ans += bit.sum(c5_to_i[c5_max] + 1) - bit.sum(c5_to_i[-c5])
        else:
            while j < i:
                j += 1
                bit.add(c5_comp[j], -1)
            
            while j > i:
                bit.add(c5_comp[j], 1)
                j -= 1

            ans += bit.sum(c5_to_i[c5_max] + 1) - bit.sum(c5_to_i[-c5])
    
    print(ans)


solve()

Submission status: Wrong Answer

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

b = []
for i in range(n):
    s = str(a[i])
    t = s.split(".")
    if len(t) == 2:
        if len(t[1]) > 5:
            pass
        else:
            b.append(a[i])
    else:
        b.append(a[i])

ans = 0
for i in range(len(b)):
    for j in range(i+1,len(b)):
        temp = int(b[i]*10**9) * int(b[j]*10**9)
        if (temp % 10**18 == 0):
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:

#import collections  
#from collections import defaultdict  
#for _ in range(int(input())):
import math
n=int(input())
#w=[int(x) for x in input().split()]
a=[float(input()) for _ in range(n)]

ans=0
for i in range(n):
    if a[i]==0:
       ans+=(n-1)
       continue
    for j in range(i+1,n):
        #x= a[i]*a[j]
        if (a[i]*a[j]).is_integer():
           ans+=1 
print(ans)