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:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#

"""
"""

from collections import defaultdict
import bisect

import sys
input = sys.stdin.readline
from decimal import *
from collections import Counter


def solve(n):
    cnt = Counter()
    n_int = 0
    for _ in range(n):
        getcontext().prec = 20
        a = input()
        da = Decimal(a)
        ia = int(da*(10**9))
        if ia%10**9 == 0:
            n_int += 1
        pmul_2 = 0
        pmul_5 = 0
        ia2 = ia
        while ((ia2 & 1) == 0 and pmul_2 < 18): 
            ia2 = ia2 >> 1
            pmul_2 += 1
        ia5 = ia
        while 1:
            if ia5 % 5 ==0:
                pmul_5 += 1
                ia5 = ia5//5
            else:
                break
        cnt[(pmul_2,pmul_5)] += 1
    ans = 0
    print(cnt)
    for pm2_1 in range(0,19):
        for pm2_2 in range(18-pm2_1,19):
            for pm5_1 in range(1,19):
                for pm5_2 in range(18-pm5_1,19):
                    ans += cnt[(pm2_1,pm5_1)]*cnt[(pm2_2,pm5_2)]
    ans -= n_int
    ans = ans//2

    print(ans)
                






def main():
    n = int(input())
    solve(n)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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 D == True:
            total += 1
        else:
            total += 0
        k += 1
    j += 1
    k = 0
print(total)

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 = input().rstrip()
    if '.' in A:
        a,b = A.split('.')
        n = int(a+b)*10**(9-len(b))
    else:
        n = int(A) * 10 ** 9
    F.append(five(n))

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
        # rint(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 = []
B = []
C2 = [0] * N
C5 = [0] * N
for i in range(N):
    s = str(input())
    A.append(s)
    ok = False
    cnt = 0
    l = len(A[-1])
    for j in range(l):
        if A[-1][j] == '.':
            ok = True
            cnt = j
    if ok:
        # 11桁になるまで+0
        if cnt == 1:
            while len(A[-1]) < 11:
                A[-1] += "0"
        # 12
        elif cnt == 2:
            while len(A[-1]) < 12:
                A[-1] += "0"
    else:
        A[-1] += ".000000000"
    tmp = ""
    for j in range(len(A[i])):
        if A[i][j] == '.':continue
        tmp += A[i][j]
    B.append(int(tmp))
    tmp = B[i]
    tmp2 = B[i]
    while tmp > 0:
        if tmp % 2 == 0:
            tmp //= 2
            C2[i] += 1
        else:
            break
    while tmp2 > 0:
        if tmp % 5 == 0:
            tmp //= 5
            C5[i] += 1
        else:
            break

Cc = [[] for _ in range(19)]
for i in range(N):
    Cc[min(18, C2[i])].append(C5[i])
for i in range(19):
    Cc[i].sort()

ans = 0
cnt99 = 0
for i in range(N):
    # 2がC2[i]個 -> 相手は最低18-C2[i]かつ、18 - C5[i]以上の個数
    M = 18 - C5[i]
    for j in range(max(0,18-C2[i]), 19):
        MM = M
        if C2[i] == 9 and C5[i] == 9 and j == 9:
            MM += 1
            cnt99+=1
        ok = -1
        ng = len(Cc[j])
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if Cc[j][mid] >= MM:
                ok = mid
            else: ng = mid
        ans += ok+1
ans //= 2
ans += cnt99 * (cnt99 - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
from decimal import Decimal


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(Decimal(input()) * 10**9)) for _ in range(n)]

ans = 0
for (x, y) in arr:
    if x >= 9 and y >= 9:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
for _ in range(N):
    A.append(int(float(input())*10**9))
ans=0
for i in range(N):
    for j in range(i+1,N):
        count2 = 0
        count5 = 0
        tmp = A[i]*A[j]
        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 count2 >= 18 and count5 >= 18:
            ans += 1
print(ans)

Submission status: Wrong Answer

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):
    c = Counter()
    for a in A:
        a += '.0'
        t = a.split('.')
        b = int(t[0]) * 10**9 + int(t[1]) * 10**(9-len(t[1]))
        n5 = 0
        n2 = 0
        while b % 2 == 0:
            n2 += 1
            b //= 2
        while b % 5 == 0:
            n5 += 1
            b //= 5
        c[(n2, n5)] += 1

    ans = 0
    for k, kk in combinations_with_replacement(c.keys(), r=2):
        if k[0] + kk[0] >= 18 and k[1] + kk[1] >= 18:
            if k == kk:
                ans += c[k] * (c[k]-1) // 2
            else:
                ans += c[k] * c[k]

    return ans


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




if __name__ == '__main__':
    main()

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-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[: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:
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-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[: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:
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-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, temp)

print(temp)

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

Submission status: Wrong Answer

Solution code:

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

l_int=[]
l_2=[]
l_4=[]
l_5=[]
l_8=[]
l_10=[]
l_100=[]
l_1000=[]
l_even=[]
ans=0
for x in a:
    if int(x)==x:l_int.append(x)
    else:
        e=math.floor(x*10**9-int(x)*10**9)/(10**9)
        if e==0.2 or e==0.4 or e==0.6 or e==0.8 :l_even.append(x)
        if e==0.5:l_2.append(x)
        if e==0.25:l_4.append(x)
        if e==0.2:l_5.append(x)
        if e==0.125:l_8.append(x)

        if x*1000//1==x*1000:l_1000.append(x)
        if x*100//1==x*100:l_100.append(x)
        if x*10//1==x*10:l_10.append(x)
        
ans+=len(l_int)*(len(l_int)-1)/2+len(l_2)*len(l_even)

for x in l_int:
    if x==1:continue
    if x//8==x/8:ans+=len(l_8)
    elif x//5==x/5:ans+=len(l_5)
    elif x//4==x/4:ans+=len(l_4)
    elif x//2==x/2:ans+=len(l_2)
    elif x//1000==x/1000:ans+=len(l_1000)
    elif x//100==x/100:ans+=len(l_100)
    elif x//10==x/10:ans+=len(l_10)

print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
N=int(input())

div_dic=defaultdict(int)
def add_fact(x):
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      div_dic[i]+=1
      if i!=x//i:
        div_dic[x//i]+=1
  return

alist=[]
int_list=[]
for _ in range(N):
  a=input()
  if "." in a:
    seisu,shosu=a.split(".")
    seisu=int(seisu)
    shosu=int(shosu.ljust(9,'0'))
    
    bunshi=10**9*seisu+shosu
    bumbo=10**9
    gcd_bb=math.gcd(bunshi,bumbo)
    bunshi//=gcd_bb
    bumbo//=gcd_bb
    
    if bunshi>1000000:
      continue
    if bumbo==1:
      int_list.append(bunshi)
      add_fact(bunshi)
    else:
      alist.append((bunshi,bumbo))
  else:
    seisu=int(a)
    int_list.append(seisu)
    add_fact(seisu)
#print(int_list,alist,div_dic)

num_int=len(int_list)
answer=num_int*(num_int-1)//2
for bunshi,bumbo in alist:
  answer+=div_dic[bumbo]

#shosudoshi
def set_fact(x):
  ret=set()
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      ret.add(i)
      ret.add(x//i)
  return ret

#print(alist)
div_dic2=defaultdict(int)
for bunshi,bumbo in alist:
  div_set=set_fact(bunshi)  
  for d in div_set:    
    answer+=div_dic2[(bumbo,d)]
    
  for d in div_set:    
    div_dic2[(d,bumbo)]+=1
#print(div_dic2)
  
print(answer)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math
N=int(input())

div_dic=defaultdict(int)
def add_fact(x):
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      div_dic[i]+=1
      if i!=x//i:
        div_dic[x//i]+=1
  return

alist=[]
int_list=[]
for _ in range(N):
  a=input()
  if "." in a:
    seisu,shosu=a.split(".")
    seisu=int(seisu)
    shosu=int(shosu.ljust(9,'0'))
    
    bunshi=10**9*seisu+shosu
    bumbo=10**9
    gcd_bb=math.gcd(bunshi,bumbo)
    bunshi//=gcd_bb
    bumbo//=gcd_bb
    
    if bunshi>10000:
      continue
    if bumbo==1:
      int_list.append(bunshi)
      add_fact(bunshi)
    else:
      alist.append((bunshi,bumbo))
  else:
    seisu=int(a)
    int_list.append(seisu)
    add_fact(seisu)
#print(int_list,alist,div_dic)

num_int=len(int_list)
answer=num_int*(num_int-1)//2
for bunshi,bumbo in alist:
  answer+=div_dic[bumbo]

#shosudoshi
def set_fact(x):
  ret=set()
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      ret.add(i)
      ret.add(x//i)
  return ret

#print(alist)
div_dic2=defaultdict(int)
for bunshi,bumbo in alist:
  div_set=set_fact(bunshi)  
  for d in div_set:    
    answer+=div_dic2[(bumbo,d)]
    
  for d in div_set:    
    div_dic2[(d,bumbo)]+=1
#print(div_dic2)
  
print(answer)

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 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 = str( 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: 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)
    ans += cnt[18-i][18-j]-me

print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
def get(a):
	if '.' not in a:
		return (int(a), 0, 0)
	a = a.split('.')
	return (int(a[0]), int(a[1]), len(a[1]))
def check(a,b,c):
	return (c == 0 or a*b >= (10 ** c)) and (a*b) % (10 ** c) == 0

def product(u,v):

	a, b, c = u
	d, e, f = v

	if b == e == 0:
		return True

	#a + b . 10 - c
	#d + e . 10 - f 

	return check(a,e,f) and check(b,d,c) and check(b,e,f+c)

count = 0
bis = [raw_input() for _ in range(n)]
ais = [get(b) for b in bis]
for i,u in enumerate(ais):
	for j in range(i+1, len(ais)):
			
		if product(u,ais[j]):
			count +=1

print count

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [input().rstrip() for i in range(n)]
ls0 = []
ls25 = []
for i in range(n):
  s = a[i]
  l = len(s)
  if "." in s:
    pt = s.index(".")
    ls0.append(l-pt-1)
    x = s[:pt]+s[pt+1:]
  else:
    ls0.append(0)
    x = s
  ix = int(x)
  c2 = 0
  while ix%2 == 0:
    c2 += 1
    ix //= 2
  c5 = 0
  ix = int(x)
  while ix%5 == 0:
    c5 += 1
    ix //= 5
  ls25.append((c2-ls0[-1],c5-ls0[-1]))
ls25.sort()
ls2 = list(zip(*ls25))[0]
from collections import defaultdict
import bisect
dic5 = defaultdict(int)
ans = 0
for i in range(n)[::-1]:
  if ls2[i] < 0:
    break
  ind = bisect.bisect_left(ls2,-ls2[i])
  if i == n-1:
    for j in range(n-2,ind-1,-1):
      dic5[ls25[j][1]] += 1
    ptr = ind
  else:
    for j in range(ptr,ind):
      dic5[ls25[j][1]] -= 1
    dic5[ls25[i+1][1]] -= 1
    ptr = ind
  for v,num in dic5.items():
    if v+ls25[i][1] >= 0:
      ans += num
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [input().rstrip() for i in range(n)]
ls0 = []
ls25 = []
for i in range(n):
  s = a[i]
  l = len(s)
  if "." in s:
    pt = s.index(".")
    ls0.append(l-pt-1)
    x = s[:pt]+s[pt+1:]
  else:
    ls0.append(0)
    x = s
  ix = int(x)
  c2 = 0
  while ix%2 == 0:
    c2 += 1
    ix //= 2
  c5 = 0
  ix = int(x)
  while ix%5 == 0:
    c5 += 1
    ix //= 5
  ls25.append((c2-ls0[-1],c5-ls0[-1]))
ls25.sort()
ls2 = list(zip(*ls25))[0]
from collections import defaultdict
import bisect
dic5 = defaultdict(int)
ans = 0
for i in range(n)[::-1]:
  if ls2[i] < 0:
    break
  ind = bisect.bisect_left(ls2,-ls2[i])
  if i == n-1:
    for j in range(n-2,ind-1,-1):
      dic5[ls25[j][1]] += 1
    ptr = ind
  else:
    for j in range(ptr,ind):
      dic5[ls25[j][1]] -= 1
    dic5[ls25[i+1][1]] -= 1
    ptr = ind
  for v,num in dic5.items():
    if v+ls25[i][1] >= 0:
      ans += num
print(ans)
print(ls25)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
def get(a):
	if '.' not in a:
		return (int(a), 0, 0)
	a = a.split('.')
	return (int(a[0]), int(a[1]), len(a[1]))
def check(a,b,c):
	return (a*b) % (10 ** c) == 0

def product(u,v):

	a, b, c = u
	d, e, f = v

	if b == e == 0:
		return True

	#a + b . 10 - c
	#d + e . 10 - f 

	return check(a,e,f) and check(b,d,c) and check(b,e,f+c)

count = 0
bis = [raw_input() for _ in range(n)]
ais = [get(b) for b in bis]
for i,u in enumerate(ais):
	for j in range(i+1, len(ais)):
			
		if product(u,ais[j]):
			count +=1

print count

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [input().rstrip() for i in range(n)]
ls0 = []
ls25 = []
for i in range(n):
  s = a[i]
  l = len(s)
  if "." in s:
    pt = s.index(".")
    ls0.append(l-pt-1)
    x = s[:pt]+s[pt+1:]
  else:
    ls0.append(0)
    x = s
  ix = int(x)
  c2 = 0
  while ix%2 == 0:
    c2 += 1
    ix //= 2
  c5 = 0
  ix = int(x)
  while ix%5 == 0:
    c5 += 1
    ix //= 5
  ls25.append((c2-ls0[-1],c5-ls0[-1]))
ls25.sort()
ls2 = list(zip(*ls25))[0]
from collections import defaultdict
import bisect
dic5 = defaultdict(int)
ans = 0
for i in range(n)[::-1]:
  if ls2[i] < 0:
    break
  ind = bisect.bisect_left(ls2,-ls2[i])
  if i == n-1:
    for j in range(n-2,ind-1,-1):
      dic5[ls25[j][1]] += 1
    ptr = ind
  else:
    for j in range(ptr,ind):
      dic5[ls25[j][1]] -= 1
    dic5[ls25[i+1][1]] -= 1
  for v,num in dic5.items():
    if v+ls25[i][1] >= 0:
      ans += num
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
fives, twos, dec = [], [], []
for i in range(n):
    r = (input())
    if '.' in r:
        dec.append(len(r) - r.index('.') - 1)
        if r[r.index('.')+1:].count('0')==dec[i]:
            r=r[:r.index('.')]
            dec[i]=0
        else:
            r = r.replace(".", "")
    else:
        dec.append(0)
    q = int(r)
    cf, ct = 0, 0
    while (q % 5 == 0):
        q /= 5
        cf += 1
    while (q % 2 == 0):
        q /= 2
        ct += 1
    fives.append(cf)
    twos.append(ct)
count = 0
for i in range(n):
    for j in range(i + 1, n):
        f,t,d= (fives[i]+fives[j]),(twos[i]+twos[j]),max(dec[i],dec[j])
        if min(f,t)>=d:
            count+=1
print(count)

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
        tmps = np.clip(tmp_list, 0, 10 ** 18)
        ans += np.count_nonzero(tmps != 10 ** 18)
    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())
A = []
B = []
C2 = [0] * N
C5 = [0] * N
for i in range(N):
    s = str(input())
    A.append(s)
    ok = False
    cnt = 0
    l = len(A[-1])
    for j in range(l):
        if A[-1][j] == '.':
            ok = True
            cnt = j
    if ok:
        # 11桁になるまで+0
        if cnt == 1:
            while len(A[-1]) < 11:
                A[-1] += "0"
        # 12
        elif cnt == 2:
            while len(A[-1]) < 12:
                A[-1] += "0"
    else:
        A[-1] += ".000000000"
    tmp = ""
    for j in range(len(A[i])):
        if A[i][j] == '.':continue
        tmp += A[i][j]
    B.append(int(tmp))
    tmp = B[i]
    tmp2 = B[i]
    while tmp > 0:
        if tmp % 2 == 0:
            tmp //= 2
            C2[i] += 1
        else:
            break
    while tmp2 > 0:
        if tmp % 5 == 0:
            tmp //= 5
            C5[i] += 1
        else:
            break

Cc = [[] for _ in range(60)]
for i in range(N):
    Cc[C2[i]].append(C5[i])
for i in range(60):
    Cc[i].sort()

ans = 0
cnt99 = 0
for i in range(N):
    # 2がC2[i]個 -> 相手は最低18-C2[i]かつ、18 - C5[i]以上の個数
    M = 18 - C5[i]
    if C2[i] == 9 and C5[i] == 9:
        cnt99+=1
        M+=1
    for j in range(max(0,18-C2[i]), 60):
        ok = -1
        ng = len(Cc[j])
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if Cc[j][mid] >= M:
                ok = mid
            else: ng = mid
        ans += ok+1

ans //= 2
ans += cnt99 * (cnt99 - 1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = list(input().split())
answerList = []

for l in range(len(N)):
    for k in range(len(N)):
        if l < k:
            multiNumber = float(N[l])*float(N[k])
            if multiNumber.is_integer():
                answerList.append(float(N[l])*float(N[k]))

print(len(answerList))

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
import heapq
from fractions import *
from decimal import *
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter

sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n - k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv


def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]


class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h + 2) * (w + 2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x

    def getgrid(self, x, y):
        return self.grid[y][x]

    def get(self, x, y):
        return self.cost[self.pos(x, y)]

    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return

    def show(self):
        for i in range(self.h + 2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i + 1)])

    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return

    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy


def so(n):
    ret = []
    for i in range(2, int(math.sqrt(n) + 2)):
        if n % i == 0:
            ret.append(i)

    if ret == []:
        return [n]
    else:
        return ret


def getnig(n):
    ni, go = 0, 0
    while n % 2 == 0:
        ni += 1
        n //= 2
    while n % 5 == 0:
        go += 1
        n //= 5

    return min(18, ni), min(18, go)


def solve():
    # n = getN()
    # nums = []
    # bunsi = [0 for i in range(100)]
    # sei = 0
    # for i in range(n):
    #     S = getS()
    #     if "." not in S:
    #         sei += 1
    #         for sso in so(int(S)):
    #             bunsi[sso] += 1
    #
    #     else:
    #         nums.append(float(S))
    #
    # print(bunsi)
    # print(nums)
    # # for num in nums:
    # #     for s in so(num):
    # #         bunsi[s] += 1
    # # for
    n = getN()
    nums = []
    nigolis = [[0 for i in range(21)] for j in range(21)]
    for i in range(n):
        num = float(getS())
        # print(num)
        # if num == 0:
        #     nigolis[18][18] += 1
        #     nums.append((18,18))
        #     continue
        num *= 10 ** 10
        # print(num)
        ni, go = getnig(num)
        # print(ni, go)
        nigolis[ni][go] += 1
        nums.append((ni, go))
    # print(nums)
    for i in range(20):
        for j in range(20):
            nigolis[i][j + 1] += nigolis[i][j]
    # for nigo in nigolis:
    #     print(nigo)
    ans = 0
    for tn, tg in nums:
        for i in range(20 - tn, 21):
            if tg == 20:
                ans += nigolis[i][-1]
            else:
                ans += nigolis[i][-1] - nigolis[i][20 - tg - 1]

        if tn >= 10 and tg >= 10:
            ans -= 1
        # print(ans)

    print(ans // 2)
    # print(Fraction(Decimal("0.3")).denominator)


def main():
    n = getN()
    for _ in range(n):
        solve()

    return


if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import defaultdict
from fractions import Fraction


def zfill(s: str) -> int:
    p = s.find('.')
    return int((s + '0'*(10-(len(s)-p) if 0 < p else 9)).replace('.', ''))


def solve(*args: str) -> str:
    n = int(args[0])
    N = defaultdict(list)
    D = defaultdict(list)

    for a in args[1:]:
        frac = Fraction(a)
        if frac.denominator <= 10000:
            N[frac.numerator].append(frac.denominator)
            D[frac.denominator].append(frac.numerator)
    
    ret = 0
    while D:
        den, DN = D.popitem()
        if 1 == den:
            m = len(DN)
            ret += m*(m-1)//2
        else:
            for num, ND in N.items():
                if num % den != 0:
                    continue

                for n_den in ND:
                    if 1 < n_den <= den:
                        continue

                    for d_num in DN:
                        if d_num % n_den != 0:
                            continue

                        ret += 1
    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

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

l_int=[]
l_2=[]
l_4=[]
l_5=[]
l_8=[]
l_10=[]
l_100=[]
l_1000=[]
l_even=[]
ans=0
for x in a:
    if int(x)==x:l_int.append(x)
    else:
        e=math.floor(x*10**9-int(x)*10**9)/(10**9)
        if e==0.2 or e==0.4 or e==0.6 or e==0.8 :l_even.append(x)
        if e==0.5:l_2.append(x)
        if e==0.25:l_4.append(x)
        if e==0.2:l_5.append(x)
        if e==0.125:l_8.append(x)

        if x*1000//1==x*1000:l_1000.append(x)
        elif x*100//1==x*100:l_100.append(x)
        elif x*10//1==x*10:l_10.append(x)
        
ans+=len(l_int)*(len(l_int)-1)/2+len(l_2)*len(l_even)

for x in l_int:
    if x==1:continue
    if x//8==x/8:ans+=len(l_8)
    if x//5==x/5:ans+=len(l_5)
    if x//4==x/4:ans+=len(l_4)
    if x//2==x/2:ans+=len(l_2)
    if x//1000==x/1000:ans+=len(l_1000)
    if x//100==x/100:ans+=len(l_100)
    if x//10==x/10:ans+=len(l_10)

print(int(ans))