Problem:


Score : 300 points

Problem Statement

You are given N real values A_1, A_2, \ldots, A_N.
Compute the number of pairs of indices (i, j)
    such that i < j and the product A_i \cdot A_j is integer.

Constraints

2 \leq N \leq 200\,000

0 < A_i < 10^4

A_i is given with at most 9 digits after the decimal.

Input

Input is given from Standard Input in the following format.

N
A_1
A_2
\vdots
A_N

Output

Print the number of pairs with integer product A_i \cdot A_j (and i < j).

Sample Input 1

5
7.5
2.4
17.000000001
17
16.000000000

Sample Output 1

3

There are 3 pairs with integer product:

7.5 \cdot 2.4 = 18

7.5 \cdot 16 = 120

17 \cdot 16 = 272

Sample Input 2

11
0.9
1
1
1.25
2.30000
5
70
0.000000001
9999.999999999
0.999999999
1.000000001

Sample Output 2

8



Sample input:
5
7.5
2.4
17.000000001
17
16.000000000


Sample output:
3

Submission status: Runtime Error

Solution code:
class BIT:
    def __init__(self, n):
        #A1 ... AnのBIT(1-indexed)
        self.BIT = [0] * (n + 1)
        self.n = n

    #A1 ~ Aiまでの和 O(logN)
    def query(self, idx):
        res_sum = 0
        while idx > 0:
            res_sum += self.BIT[idx]
            idx -= idx & (-idx)
        return res_sum

    #Ai += x O(logN)
    def add(self, idx, x):
        while idx <= self.n:
            self.BIT[idx] += x
            idx += idx&(-idx)
        return
def get_int(f):
    if "." not in f:
        return int(f),0
    return int(f.replace(".","")),len(f)-f.index(".")-1
n = int(input())
p = []
for i in range(n):
    a, b = get_int(input())
    c, d = 0, 0
    while a % 2 == 0:
        c += 1
        a //= 2
    while a % 5 == 0:
        d += 1
        a //= 5
    c -= b
    d -= b
    p.append(c * 300000 + d)
p.sort()
for i in range(n):
    p[i] = (p[i] // 300000, p[i] % 300000)
now = n - 1
t = BIT(50)
ans = 0
for i in range(n):
    for j in range(now, i, -1):
        if p[i][0] + p[j][0] >= 0:
            t.add(-p[j][1] + 25, 1)
            now -= 1
        else:
            break
    if now < i:
        t.add(-p[i][1] + 25, -1)
    ans += max(0, t.query(25 + p[i][1]))

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
A=[]
PRECISION_DIGITS=9
NO_ENTRY = 0
cnt=np.full((PRECISION_DIGITS*2,PRECISION_DIGITS*2),NO_ENTRY,int)
# cnt=np.zeros((PRECISION_DIGITS*2,PRECISION_DIGITS*2),int)

# print(cnt)

for n in range(N):
	tmpA = float(input())
	tmpA = int(tmpA*10**PRECISION_DIGITS)
	#print(tmpA)

	five = 0
	two = 0
	# (10**9) -> (two,five)=(9,9)
	# min = 10**-9, ignore < 10**9 ???
	while (tmpA % 5) == 0 and five < PRECISION_DIGITS*2:
		five += 1
		tmpA //= 5
	while (tmpA % 2) == 0 and two < PRECISION_DIGITS*2:
		two += 1
		tmpA //= 2

	if cnt[two][five] == 0:
		cnt[two][five]=1
	else:
		cnt[two][five]+=1

# print(cnt)
ans = 0

for x1 in range(PRECISION_DIGITS*2):
	for y1 in range(PRECISION_DIGITS*2):
		if cnt[x1][y1] == NO_ENTRY:
			continue

		for x2 in range(PRECISION_DIGITS*2):
			for y2 in range(PRECISION_DIGITS*2):
				if cnt[x2][y2] == NO_ENTRY:
					continue
				# 2**a(a>=0) and 5**b(b>=0) => integer
				if 0 <= x1+x2 - PRECISION_DIGITS*2 and 0 <= y1+y2 -PRECISION_DIGITS*2:
					if x1 == x2 and y1 == y2:
						# same entry
						# Total number of combinations choose 2 items
						# nC2 = n*(n-1)/2
						ans += int((cnt[x1][y1]*(cnt[x2][y2]-1))//2)
					else:
						ans += cnt[x1][y1]*cnt[x2][y2]

		# count up completed entry
		cnt[x1][y1] = NO_ENTRY

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=[Decimal(input()) for x in range(n)]
count=0
for i in range(1,n):
  for j in range(n-i):
    with localcontext() as ctx:
      ans=A[i-1]*A[i+j]
      ans.to_integral_exact()
      count += 1 if not ctx.flags[Inexact] else 0 
print(count)

Submission status: Runtime Error

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

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

B=[]

for i in range(N):
  dev2,dev5=0,0
  while A[i]%2==0:
    dev2+=1
    A[i]//=2
  while A[i]%5==0:
    dev5+=1
    A[i]//=5
  dat[dev2][dev5]+=1
  B.append([dev2,dev5])
  
for i in range(19):
  for j in range(19):
    for k in range(i+1):
      for l in range(j+1):
        rui[k][l]+=dat[i][j]
  
ans=0
for i in range(N):
  dev2,dev5=B[i]
  t_dev2,t_dev5=18-dev2,18-dev5
  if dev2>=t_dev2 and dev5>=t_dev5:
    ans-=1
  ans+=rui[t_dev2][t_dev5]

print(ans//2)

Submission status: Runtime Error

Solution code:
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;
            Dictionary<Tuple<int, int>, int> bucket = new Dictionary<Tuple<int, int>, int>();
            N = Convert.ToInt32(Console.ReadLine());
            numNode a;
            for (int i = 0; i < N; i++)
            {
                var theNumber = Console.ReadLine();
                var pos = theNumber.IndexOf('.');
                if (pos == -1)
                {
                    a = new numNode(theNumber);
                }
                else
                {
                    var intpart = Convert.ToInt64(theNumber.Substring(0, pos));
                    var powOfDen = Convert.ToInt64(Math.Pow(10, Convert.ToDouble(theNumber.Length - pos - 1)));
                    var decipart = Convert.ToInt64(theNumber.Substring(pos + 1));
                    a = new numNode(intpart * powOfDen + decipart, powOfDen);
                }
                if (bucket.ContainsKey(a.GetTuple()))
                {
                    bucket[a.GetTuple()] += 1;
                }
                else
                {
                    bucket[a.GetTuple()] = 1;
                }
            }

            Int64 s = 0;
            foreach (var it in bucket.Keys)
            {
                var x1 = it.Item1;
                var y1 = it.Item2;
                var r1 = bucket[it];
                foreach (var it2 in bucket.Keys)
                {
                    var x2 = it2.Item1;
                    var y2 = it2.Item2;
                    var r2 = bucket[it2];
                    if (x1 + x2 >= 0 && y1 + y2 >= 0)
                    {
                        if (lessThan(it , it2))
                        {
                            s += r1 * r2;
                        }
                        else if (it == it2)
                        {
                            s += (r1 * (r1 - 1)) / 2;
                        }
                    }
                }
            }
            Console.WriteLine(s);
        }
        private static bool lessThan(Tuple<int,int> a,Tuple<int,int> b)
        {
            if(a.Item1==b.Item1)
            {
                return a.Item2 < b.Item2;
            }
            else
            {
                return a.Item1 < b.Item1;
            }
        }
       
    }
    
    
    
    class numNode
    {
        private int c2 { get; set; }
        private int c5 { get; set; }

        public numNode() { }

        public numNode(Int64 num, Int64 den)
        {
            c2 = 0;
            while (num % 2 == 0)
            {
                c2++;
                num /= 2;
            }
            while (den % 2 == 0)
            {
                c2--;
                den /= 2;
            }
            c5 = 0;
            while (num % 5 == 0)
            {
                c5++;
                num /= 5;
            }
            while (den % 5 == 0)
            {
                c5--;
                den /= 5;
            }
        }
        public numNode(string v)
        {
            int num = Convert.ToInt32(v);
            c2 = 0;
            while (num % 2 == 0)
            {
                c2++;
                num /= 2;
            }
            c5 = 0;
            while (num % 5 == 0)
            {
                c5++;
                num /= 5;
            }
        }
        public Tuple<int, int> GetTuple()
        {
            return new Tuple<int, int>(c2, c5);
        }

    }
}

Submission status: Runtime Error

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

def calc(n):
  cnt_2=0
  cnt_5=0
  while n%2==0 and cnt_2<18:
    cnt_2+=1
    n//=2
  while n%5==0 and cnt_5<18:
    cnt_5+=1
    n//=5
  return [cnt_2,cnt_5]

n=int(input())
dic=collections.defaultdict(int)
ans=0
for _ in range(n):
  tmp=input()
  if '.' in tmp:
    pos=tmp.index('.')
    d=len(tmp)-(pos+1)
    tmp=tmp[:pos]+tmp[pos+1:]+'0'*(9-d)
  else:
    tmp+='0'*9
  tmp=int(tmp)
  cnt_2,cnt_5=calc(tmp)
  dic[(cnt_2,cnt_5)]+=1
  if 18<=min(cnt_2*2,cnt_5*2):
    ans-=1
for a1,b1 in dic.keys():
  for a2,b2 in dic.keys():
    if min(a1+a2,b1+b2)>=18:
      ans+=dic[(a1,b1)]*dic[(a2,b2)]
print(ans//2)

Submission status: Runtime Error

Solution code:
import sys
from math import gcd
from collections import defaultdict
sys.setrecursionlimit(10**6)
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return False
            t <<= 1
    return True
def findFactorRho(n):
    m = 1 << n.bit_length() // 8 + 1
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r-k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x-ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n//g): return n//g
def primeFactor(N):
    i = 2
    ret = defaultdict(int)
    n = N
    mrFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i%2
        if i == 101 and n >= 2**20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    mrFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)}
    return ret
def main():
    c = [[0]*50 for _ in range(50)]
    r = 0
    for a in [*open(0)][1:]:
        p = primeFactor(round(float(a)*10**9))
        a, b = p[2], p[5]
        r += sum(sum(d[max(0,18-b):]) for d in c[max(0,18-a):])
        c[a][b] += 1
    print(r)
main()

Submission status: Runtime Error

Solution code:
from math import gcd
from collections import defaultdict
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return False
            t <<= 1
    return True
def findFactorRho(n):
    m = 1 << n.bit_length() // 8 + 1
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r-k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x-ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n//g): return n//g
def primeFactor(N):
    i = 2
    ret = defaultdict(int)
    n = N
    mrFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i%2
        if i == 101 and n >= 2**20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    mrFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if mrFlg > 0: ret = {x: ret[x] for x in sorted(ret)}
    return ret
def main():
    c = [[0]*50 for _ in range(50)]
    r = 0
    for a in [*open(0)][1:]:
        p = primeFactor(round(float(a)*10**9))
        a, b = p[2], p[5]
        r += sum(sum(d[max(0,18-b):]) for d in c[max(0,18-a):])
        c[a][b] += 1
    print(r)
main()

Submission status: Runtime Error

Solution code:
N = int(input())
B = list(map(int, input().split()))
tot = 0

A = []
for i in range(N):
  if B[i] != 0:
    A.append(B[i])
  
for i in range(len(A)):
    for j in range(len(A)-i-1):
        tot = tot + A[i]*A[i+j+1] % 200003

print(tot)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
tot = 0
    
for i in range(N):
    for j in range(N-i-1):
        tot = tot + A[i]*A[i+j+1] % 200003

print(tot)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
n = int(input())
a = []
r = [[0 for i in range(18)] for j in range(18)]
for i in range(n):
    d = Decimal(input())
    d *= 10**9
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[d2][d5] += 1
ans = 0

for x , y in a:
    for i in range(18):
        for j in range(18):
            if min(i+x,j+y) >= 18:
                ans += r[i][j]
    if min(x,y) >= 9:
        ans -= 1
print(ans//2)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
n = int(input())
a = []
r = [[0 for i in range(14)] for j in range(14)]
for i in range(n):
    d = Decimal(input())
    d *= 10**9
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[d2][d5] += 1
ans = 0

for x , y in a:
    for i in range(14):
        for j in range(14):
            if min(i+x,j+y) >= 18:
                ans += r[i][j]
    if min(x,y) >= 9:
        ans -= 1
print(ans//2)

Submission status: Runtime Error

Solution code:
from decimal import Decimal
n = int(input())
a = []
r = [[0 for i in range(14)] for j in range(14)]
for i in range(n):
    d = Decimal(input())
    d *= 10**9
    d = int(d)
    d2 = 0
    d5 = 0
    while True:
        if d % 2 != 0 and d % 5 != 0:
            break
        if d % 2 == 0:
            d //= 2
            d2 += 1
        if d % 5 == 0:
            d //= 5
            d5 += 1
    a.append((d2,d5))
    r[d2][d5] += 1
ans = 0

for x , y in a:
    for i in range(14):
        for j in range(14):
            if min(i+x,j+y) >= 18:
                ans += r[i][j]
    if min(x,y) >= 9:
        ans -= 1
print(ans//2)

Submission status: Runtime Error

Solution code:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
    m = [[0] * 20 for _ in range(20)]
    Ad = []
    for a in A:
        p = a.index('.') if a.count('.') > 0 else len(a) - 1
        l = len(a) - p - 1
        n = int(a.replace('.', '') + '0' * (9 - l))
        d2, d5 = 0, 0
        while n % 2 == 0:
            d2 += 1
            n //= 2
        while n % 5 == 0:
            d5 += 1
            n //= 5
        m[d2][d5] += 1
        Ad.append((d2, d5))
    for i in range(19, 0, -1):
        for j in range(20):
            m[i - 1][j] += m[i][j]
    for i in range(20):
        for j in range(19, 0, -1):
            m[i][j - 1] += m[i][j]
    ans = 0
    for d2, d5 in Ad:
        dd2, dd5 = 18 - d2, 18 - d5
        ans += m[dd2][dd5]
        if d2 >= dd2 and d5 >= dd5:
            ans -= 1
    print(ans // 2)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    A = [input().rstrip() for _ in range(N)]
    main(N, A)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(float, read().split())
    M = [[0] * 19 for _ in range(19)]
    
    minus = 0
    for i, a in enumerate(A):
        a *= 10 ** 9
        a = int(a)
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (min(f2, 18), min(f5, 18))
        M[f2][f5] += 1
        if f2 > 8 and f5 > 8:
            minus += 1
        
    
    #for m in M:
    #    print(m)
    
    for i in range(18, 0, -1):
        for j in range(18, -1, -1):
            M[i-1][j] += M[i][j]
    
    for i in range(18, -1, -1):
        for j in range(18, 0, -1):
            M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    #for m in M:
    #    print(m)


if __name__ == "__main__":
    run()

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(float, read().split())
    M = [[0] * 19 for _ in range(19)]
    
    minus = 0
    for i, a in enumerate(A):
        a *= 10 ** 9
        a = int(a)
        f2 = 0
        f5 = 0
        while True:
            if not a % 2:
                f2 += 1
                a = a // 2
            else:
                break
        while True:
            if not a % 5:
                f5 += 1
                a = a // 5
            else:
                break
        A[i] = (f2, f5)
        M[f2][f5] += 1
        if f2 > 8 and f5 > 8:
            minus += 1
        
    
    #for m in M:
    #    print(m)
    
    for i in range(18, 0, -1):
        for j in range(18, -1, -1):
            M[i-1][j] += M[i][j]
    
    for i in range(18, -1, -1):
        for j in range(18, 0, -1):
            M[i][j-1] += M[i][j]

    ans = 0
    for f2, f5 in A:
        ans += M[max(18-f2, 0)][max(18-f5, 0)]
        
    print((ans-minus)//2)
    
    #for m in M:
    #    print(m)


if __name__ == "__main__":
    run()

Submission status: Runtime Error

Solution code:
import numpy as np
from decimal import Decimal

N = int(input())

nums = [Decimal(input()) for _ in range(N)]

two_fives = []


for i, num in enumerate(nums):
    int_converted = int(num * (10**9))
    
    two_div_count = 0
    while int_converted % 2 == 0:
        two_div_count += 1
        int_converted //= 2
    
    five_div_count = 0
    while int_converted % 5 == 0:
        five_div_count += 1
        int_converted //= 5

    two_fives.append((two_div_count,five_div_count))


ok_count = 0

two_five_exists = np.zeros((19,19), dtype=int)

for i in range(N):    
    two_count, five_count = two_fives[i]
    ok_count += two_five_exists[two_count, five_count]
    
    two_pair = min(18, 18 - two_count)
    five_pair = min(18, 18 - five_count)
    two_five_exists[two_pair:, five_pair:] += 1

print(ok_count)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())

nums = [float(input()) for _ in range(N)]

two_fives = []


for i, num in enumerate(nums):
    int_converted = int(num * (10**9))
    
    two_div_count = 0
    while int_converted % 2 == 0:
        two_div_count += 1
        int_converted //= 2
    
    five_div_count = 0
    while int_converted % 5 == 0:
        five_div_count += 1
        int_converted //= 5

    two_fives.append((two_div_count,five_div_count))


ok_count = 0

two_five_exists = np.zeros((19,19), dtype=int)

for i in range(N):    
    two_count, five_count = two_fives[i]
    ok_count += two_five_exists[two_count, five_count]
    
    two_pair = 18 - two_count
    five_pair = 18 - five_count    
    two_five_exists[two_pair:, five_pair:] += 1

print(ok_count)

Submission status: Runtime Error

Solution code:
N = int(input())

nums = [float(input()) for _ in range(N)]

two_fives = []


for i, num in enumerate(nums):
    int_converted = num * (10**9)
    assert int_converted.is_integer()
    int_converted = int(int_converted)

    two_div_count = 0
    while int_converted % 2 == 0:
        two_div_count += 1
        int_converted //= 2
        
    
    five_div_count = 0
    while int_converted % 5 == 0:
        five_div_count += 1
        int_converted //= 5

    two_fives.append((two_div_count,five_div_count))


ok_count = 0
for i in range(N):
    for j in range(i+1,N):
        two_sum = two_fives[i][0] + two_fives[j][0]
        five_sum = two_fives[i][1] + two_fives[j][1]
        if two_sum >= 18 and five_sum >= 18:
            ok_count += 1

print(ok_count)

Submission status: Runtime Error

Solution code:
def main(n,a):
  k=40
  mp=[[0]*k for _ in range(k)]
  o=k//2
  ary=[]
  for i in range(n):
    b=list(a[i].split('.'))
    b.append('0')
    x=int(b[0])
    y=int((b[1]+'0'*9)[:9])
    x=x*pow(10,9)+y
    # x10^9
    cnt5=-9
    xx=x
    while xx>1:
      if xx%5==0:
        cnt5+=1
        xx//=5
      else:
        break
    cnt2=-9
    xx=x
    while xx>1:
      if xx%2==0:
        cnt2+=1
        xx//=2
      else:
        break
    #if 0<=cnt5+o<23 and 0<=cnt2+o<23:
    mp[cnt5+o][cnt2+o]+=1
    ary.append([cnt5+o,cnt2+o])

  ans=0
  for i in range(k-1,0,-1):
    for j in range(k):
      mp[j][i-1]+=mp[j][i]
  for i in range(k-1,0,-1):
    for j in range(k):
      mp[i-1][j]+=mp[i][j]
  for x,y in ary:
    if x>=o and y>=o:
      i=1
    else:
      i=0
    x-=o
    x*=-1
    x+=o
    y-=o
    y*=-1
    y+=o
    ans+=mp[x][y]-i
  print(ans//2)
  #mp[o,o]+=10
  #print(mp)

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

Submission status: Runtime Error

Solution code:
from numba import njit
import numpy as np
@njit
def main(n,a):
  k=60
  mp=np.zeros((k,k),np.int32)
  o=k//2
  ary=[]
  for i in range(n):
    b=list(a[i].split('.'))
    b.append('0')
    x=int(b[0])
    y=int((b[1]+'0'*9)[:9])
    x=x*pow(10,9)+y
    # x10^9
    cnt5=-9
    xx=x
    while xx>1:
      if xx%5==0:
        cnt5+=1
        xx//=5
      else:
        break
    cnt2=-9
    xx=x
    while xx>1:
      if xx%2==0:
        cnt2+=1
        xx//=2
      else:
        break
    #if 0<=cnt5+o<23 and 0<=cnt2+o<23:
    mp[cnt5+o,cnt2+o]+=1
    ary.append([cnt5+o,cnt2+o])

  ans=0
  for i in range(k-1,0,-1):
    for j in range(k):
      mp[j][i-1]+=mp[j][i]
  for i in range(k-1,0,-1):
    for j in range(k):
      mp[i-1][j]+=mp[i][j]
  for x,y in ary:
    if x>=o and y>=o:
      i=1
    else:
      i=0
    x-=o
    x*=-1
    x+=o
    y-=o
    y*=-1
    y+=o
    ans+=mp[x,y]-i
  print(ans//2)
  #mp[o,o]+=10
  #print(mp)

n=int(input())
a=np.array([input() for _ in range(n)])
main(n,a)

Submission status: Runtime Error

Solution code:
from numba import njit
import numpy as np
def main(n,a):
  mp=np.zeros((40,40),np.int32)
  o=20
  ary=[]
  for i in range(n):
    b=list(a[i].split('.'))
    b.append('0')
    x=int(b[0])
    y=int((b[1]+'0'*9)[:9])
    x=x*pow(10,9)+y
    # x10^9
    cnt5=-9
    xx=x
    while xx>1:
      if xx%5==0:
        cnt5+=1
        xx//=5
      else:
        break
    cnt2=-9
    xx=x
    while xx>1:
      if xx%2==0:
        cnt2+=1
        xx//=2
      else:
        break
    #if 0<=cnt5+o<23 and 0<=cnt2+o<23:
    mp[cnt5+o,cnt2+o]+=1
    ary.append([cnt5+o,cnt2+o])

  ans=0
  for x,y in ary:
    if x>=o and y>=o:
      i=1
    else:
      i=0
    x-=o
    x*=-1
    x+=o
    y-=o
    y*=-1
    y+=o
    ans+=np.sum(mp[x:,y:])-i
  print(ans//2)
  #mp[o,o]+=10
  #print(mp)

n=int(input())
a=np.array([input() for _ in range(n)])
main(n,a)

Submission status: Runtime Error

Solution code:
from numba import njit
import numpy as np
def main(n,a):
  mp=np.zeros((23,23),np.int32)
  o=11
  ary=[]
  for i in range(n):
    b=list(a[i].split('.'))
    b.append('0')
    x=int(b[0])
    y=int((b[1]+'0'*9)[:9])
    x=x*pow(10,9)+y
    # x10^9
    cnt5=-9
    xx=x
    while xx>1:
      if xx%5==0:
        cnt5+=1
        xx//=5
      else:
        break
    cnt2=-9
    xx=x
    while xx>1:
      if xx%2==0:
        cnt2+=1
        xx//=2
      else:
        break
    mp[cnt5+o,cnt2+o]+=1
    if 0<=cnt5+o<23 and 0<=cnt2+o<23:
      ary.append([cnt5+o,cnt2+o])

  ans=0
  for x,y in ary:
    if x>=o and y>=o:
      i=1
    else:
      i=0
    x-=o
    x*=-1
    x+=o
    y-=o
    y*=-1
    y+=o
    ans+=np.sum(mp[x:,y:])-i
  print(ans//2)
  #mp[o,o]+=10
  #print(mp)

n=int(input())
a=np.array([input() for _ in range(n)])
main(n,a)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [[0 for j in range(19)] for i in range(19)]
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 = count2 + 10 - len(A) + A.find('.')
        count5 = count5 + 10 - len(A) + A.find('.')
    else:
        count2 += 9
        count5 += 9
    a[count2][count5] += 1
ans=0
for i in range(19):
    for i2 in range(19):
        for j in range(19):
            for j2 in range(19):
                if i + i2 >= 18 and j + j2 >= 18 and ( i < i2 or i == i2 and j <= j2) and a[i][j] >0 and a[i2][j2] > 0:
                    if i == i2 and j == j2:
                        ans += a[i][j] * (a[i][j]-1) // 2
                    else:
                        ans += a[i][j] * a[i2][j2]
print(ans)

Submission status: Runtime Error

Solution code:
from numba import njit
import numpy as np
def main(n,a):
  mp=np.zeros((23,23),np.int32)
  o=11
  ary=[]
  for i in range(n):
    b=list(a[i].split('.'))
    b.append('0')
    x=int(b[0])
    y=int((b[1]+'0'*9)[:9])
    x=x*pow(10,9)+y
    # x10^9
    cnt5=-9
    xx=x
    while xx>1:
      if xx%5==0:
        cnt5+=1
        xx//=5
      else:
        break
    cnt2=-9
    xx=x
    while xx>1:
      if xx%2==0:
        cnt2+=1
        xx//=2
      else:
        break
    mp[cnt5+o,cnt2+o]+=1
    ary.append([cnt5+o,cnt2+o])

  ans=0
  for x,y in ary:
    if x>=o and y>=o:
      i=1
    else:
      i=0
    x-=o
    x*=-1
    x+=o
    y-=o
    y*=-1
    y+=o
    ans+=np.sum(mp[x:,y:])-i
  print(ans//2)

n=int(input())
a=np.array([input() for _ in range(n)])
main(n,a)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[input() for _ in range(n)]
import numpy as np
mp=np.zeros((21,21),np.int32)
ary=[]
for i in range(n):
  b=list(a[i].split('.'))
  b.append('0')
  x=int(b[0])
  y=int((b[1]+'0'*9)[:9])
  x=x*pow(10,9)+y
  # x10^9
  cnt5=-9
  xx=x
  while xx>1:
    if xx%5==0:
      cnt5+=1
      xx//=5
    else:
      break
  cnt2=-9
  xx=x
  while xx>1:
    if xx%2==0:
      cnt2+=1
      xx//=2
    else:
      break
  mp[cnt5+10,cnt2+10]+=1
  ary.append([cnt5+10,cnt2+10])

ans=0
for x,y in ary:
  if x>=10 and y>=10:
        i=1
  else:
    i=0
  x-=10
  x*=-1
  x+=10
  y-=10
  y*=-1
  y+=10
  ans+=np.sum(mp[x:,y:])-i
print(ans//2)

#mp[10,10]+=10
#print(mp)


"""
5
0.2
2
5
10
0.5

5
2.4
7.5
0.16
6.15
10

"""

Submission status: Runtime Error

Solution code:
N = int(input())
a = [[0 for j in range(19)] for i in range(19)]
for i in range(N):
    A=input()
    # tmp = int(float(A) * 10**9)
    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 = count2 + 10 - len(A) + A.find('.')
        count5 = count5 + 10 - len(A) + A.find('.')
    else:
        count2 += 9
        count5 += 9
    a[count2][count5] += 1
ans=0
for i in range(19):
    for i2 in range(19):
        for j in range(19):
            for j2 in range(19):
                if i + i2 >= 18 and j + j2 >= 18 and ( i < i2 or i == i2 and j <= j2) and a[i][j] >0 and a[i2][j2] > 0:
                    if i == i2 and j == j2:
                        ans += a[i][j] * (a[i][j]-1) // 2
                    else:
                        ans += a[i][j] * a[i2][j2]
print(ans)

Submission status: Runtime Error

Solution code:
class cumsum2D:
    def __init__(self, data):
        self.N = len(data)
        self.M= len(data[0])
        self.cum = [[0] * (self.M + 1) for _ in range(self.N + 1)]
        for i in range(self.N):
            for j in range(self.M):
                self.cum[i + 1][j + 1] = self.cum[i][j + 1] + self.cum[i + 1][j] - self.cum[i][j] + data[i][j]

    def get(self,x1,y1,x2,y2):
        """
        長方形の領域 [x1,x2)*[y1,y2) の範囲内にインプットされた数字の和を取る
        """
        return self.cum[x2][y2] - self.cum[x1][y2] - self.cum[x2][y1] + self.cum[x1][y1]

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 (min(cnt1,18), min(cnt2,18))

def digit_lift(S, l):
    if '.' in S:
        a, b = S.split('.')
        n = int(a + b) * 10 ** (l - len(b))
    else:
        n = int(S) * 10 ** l
    return n

data = [[0]*18 for _ in range(18)]

N = int(input())
Q = set()
for _ in range(N):
    A = digit_lift(input().rstrip(),9)
    x, y = five(A)
    data[x][y] += 1
    Q.add((x,y))

cum = cumsum2D(data)
res = 0
for x, y in Q:
    res += cum.get(18-x,18-y,-1,-1)*data[x][y]
print((res-2*data[9][9])//2)