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: Time Limit Exceeded

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(-25, 25):
    for k in range(-25, 25):
        for j in range(-12, 13):        
            for l in range(-12, 13):
                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: Time Limit Exceeded

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(-25, 25):
    for j in range(-15, 15):
        for k in range(-25, 25):
            for l in range(-15, 15):
                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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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(-30, 30):
            for l in range(-15, 15):
                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: Time Limit Exceeded

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(-20, 20):
        for k in range(-30, 30):
            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: Time Limit Exceeded

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

def main():
  n = int(input())
  a = [float(input()) for _ in range(n)]
  
  ans = 0
  count = 0
  
  for i in range(n):
    listJ = list(range(i + 1, n))
    for j in listJ:
      if a[i] - int(a[i]) == 0 and a[j] - int(a[j]) == 0:
        count += 1
      else:
        ans = (a[i]*10) * (a[j]*10)
        ans = ans*0.01
      if ans - int(ans) == 0:
        count += 1
  print(count)

main()

Submission status: Time Limit Exceeded

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


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

INF = 2**62-1


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


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


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


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


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


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

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


def mt(f):
    import time

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

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

    return wrap

from fractions import Fraction

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

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

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


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

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

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

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

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



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
from decimal import Decimal

number_set = list()
result_set = list()
i = 1
u = 0

a = int(input())
while i <= a:
    number_set.append(Decimal(input()))
    i += 1


for pair in itertools.combinations(number_set, 2):
    if (pair[0] * pair[1])-int((pair[0] * pair[1])) == 0:
        u += 1

print(u)

Submission status: Time Limit Exceeded

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(-35, 35):
    for j in range(-20, 20):
        for k in range(-35, 35):
            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: Time Limit Exceeded

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

def main():
  n = int(input())
  a = [float(input()) for _ in range(n)]
  
  ans = 0
  count = 0
  
  for i in range(n):
    listJ = list(range(i + 1, n))
    for j in listJ:
      if a[i] - int(a[i]) == 0 and a[j] - int(a[j]) == 0:
        count += 1
      else:
        ans = (a[i]*10000) * (a[j]*10000)
        ans = ans*0.00000001
      if ans - int(ans) == 0:
        count += 1
  print(count)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=[]
M=[]
for i in range(n):
    s=input()
    if '.' in s:
        u=s.index('.')
        a=int(s[:u]+s[u+1:])
        b=len(s)-u-1
        L.append(a)
        M.append(b)
    else:
        L.append(int(s))
        M.append(0)
ans=0
for i in range(n):
    for j in range(i+1,n):
        dat=L[i]*L[j]
        ld=M[i]+M[j]
        N=10**ld
        c=dat//N
        if c*N==dat:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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:
        C.append(A[i])
    elif A[i] > 1:
        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: Time Limit Exceeded

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(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cou = 0
nl = []
for i in range(n):
  a = float(input())
  nl.append(a)
  if i >= 1:
    for j in range(len(nl)-1):
      total = a * nl[j]
      if total.is_integer() == True and j != a:
          cou += 1
print(cou)

Submission status: Time Limit Exceeded

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

from decimal import Decimal

def get_primes(n):
	divs = defaultdict(int)
	if n == 0: return divs
	for i in [2,5]:
		c = 0
		while n % i == 0:
			n = n // i
			c += 1
		if c > 0:
			divs[i] = c
	return divs

L = 10**9
N = ri()
A = []
for i in range(N):
	d = Decimal(rs())
	A.append(int(d*L))
#print(A)

R = [0] * N
for i, a in enumerate(A):
	R[i] = A[i] % L
#print(R)

M = 18
K = 0
C = []
D = []
for i in range(N):
	r = R[i]
	a = A[i]
	if r > 0:
		ps = get_primes(a)
		C.append([min(ps[2], M), min(ps[5], M)])
	else:
		ps = get_primes(a)
		D.append([min(ps[2], M), min(ps[5], M)])
#print('C',C)
#print('D',D)

h = defaultdict(int)
ans0 = 0
for c in C:
	d = [M-c[0], M-c[1]]
	i, j = d[0], d[1]
	for i in range(d[0], M+1):
		for j in range(d[1], M+1):
			if (i, j) in h:
				ans0 += h[(i,j)] - (c == (i,j))
	h[tuple(c)] += 1

ans1 = len(D)*(len(D)-1)//2

ans2 = 0
for c in D:
	d = [M-c[0], M-c[1]]
	for i in range(d[0], M+1):
		for j in range(d[1], M+1):
			if (i, j) in h:
				ans2 += h[(i,j)] - (c == (i,j))
#print(ans0, ans1, ans2)
ans = ans0 + ans1 + ans2
print(ans)

Submission status: Time Limit Exceeded

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

def main():
  n = int(input())
  a = [float(input()) for _ in range(n)]
  
  ans = 0
  count = 0
  
  for _ in range(n):
    for j in range(_ + 1, n):
      if a[_] - int(a[_]) == 0 and a[j] - int(a[j]) == 0:
        count += 1
      else:
        ans = (a[_]*10000) * (a[j]*10000)
        ans = ans*0.00000001
      if ans - int(ans) == 0:
        count += 1
  print(count)

main()

Submission status: Time Limit Exceeded

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.00001 and A[i] < 1:
        C.append(A[i])
    elif A[i] > 1:
        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: Time Limit Exceeded

Solution code:
import math


n = int(input())

numbers = []

for _ in range(n):
    numbers.append(int(float(input()) * 1e+9))

int_counter = 0

mask = '000000000000000000'

for i in range(n - 1):
    number = numbers[i]

    for j in range(i + 1, n):
        product = number * numbers[j]

        if str(product)[-18:] == mask:
            int_counter += 1

print(int_counter)

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = [Fraction(input()) for _ in [0] * N]

    ans = 0
    for i in range(N - 1):
        d1 = A[i].denominator
        n1 = A[i].numerator
        for j in range(i + 1, N):
            d2 = A[j].denominator
            n2 = A[j].numerator
            if not n1 % d2 and not n2 % d1:
                ans += 1
    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [float(input()) for i in range(N)]
ans = 0
for i in a:
    if 0 < (i % 1) < 10**(-4):
        a.remove(i)
b = []
c = []
for i in a:
    if i.is_integer():
        b.append(i)
    else:
        c.append(i)
L = len(b)
M = len(c)
ans += int(L * (L-1) / 2)
for i in range(M-1):
    for j in range(i+1, M):
        if (c[i]*c[j]).is_integer():
            ans += 1
for i in range(M):
    for j in range(L):
        if (c[i]*b[j]).is_integer():
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import decimal
import itertools
N=int(input())
nums=[]
count=0
for i in range(N):
  a=decimal.Decimal(input())
  nums.append(a)
combination = list(itertools.combinations(nums, 2))

for i in range(int(N*(N-1)/2)):
	b, c=combination[i]
	if b*c==int(b*c):
		count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
N = int(N)
A = list()
i = 0
j = 1
s = 0
for i in range (N):
    a = input()
    a = float(a) * 10
    A.append(a)
for i in range (N - 1):
    I = i
    for i in range (j):
        o = A[i] * A[j] / 100
        if o.is_integer() == True:
            s = s + 1
        i = i + 1
    j = j + 1
    i = 0
print(s)

Submission status: Time Limit Exceeded

Solution code:
N = input()
N = int(N)
A = list()
i = 0
j = 1
s = 0
for i in range (N):
    a = input()
    a = float(a) * 1000
    A.append(a)
for i in range (N - 1):
    I = i
    for i in range (j):
        o = A[i] * A[j] / 1000000
        if o.is_integer() == True:
            s = s + 1
        i = i + 1
    j = j + 1
    i = 0
print(s)

Submission status: Time Limit Exceeded

Solution code:
from decimal import Decimal
N = int(input())
nu=[]
de=[]
integ=[]
for i in range(N):
    a=input()
    aa=Decimal(a).as_integer_ratio() #(1,3)など
    if aa[1]==1:
        integ.append(aa[0])
    elif aa[1]<10**3:
        nu.append(aa[0])
        de.append(aa[1])
ans=int(len(integ)*(len(integ)-1)/2)
for i in range(len(nu)):
    for j in range(len(integ)):
        if integ[j]%de[i]==0:
            ans+=1
for i in range(len(nu)-1):
    for j in range(i+1,len(nu)):
        if nu[i]%de[j]==0:
            if nu[j]%de[i]==0:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
N = int(N)
A = list()
i = 0
j = 1
s = 0
for i in range (N):
    a = input()
    a = float(a) * 10000
    A.append(a)
for i in range (N - 1):
    I = i
    for i in range (j):
        o = A[i] * A[j] / 100000000
        if o.is_integer() == True:
            s = s + 1
        i = i + 1
    j = j + 1
    i = 0
print(s)

Submission status: Time Limit Exceeded

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

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

for _ in range(n):
  for j in range(_ + 1, n):
    if a[_] - int(a[_]) == 0 and a[j] - int(a[j]) == 0:
      count += 1
    else:
      ans = (a[_]*10000) * (a[j]*10000)
      ans = ans*0.00000001
      if ans - int(ans) == 0:
      	count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [float(input()) for i in range(n)]
  
ans = 0
count = 0

for _ in range(n):
  for j in range(_ + 1, n):
    if a[_] - int(a[_]) == 0 and a[j] - int(a[j]) == 0:
      count += 1
    else:
      ans = (a[_]*10000) * (a[j]*10000)
      ans = ans*0.00000001
      if ans - int(ans) == 0:
      	count += 1
print(count)

Submission status: Time Limit Exceeded

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


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

INF = 2**62-1


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


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


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


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


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


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

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


def mt(f):
    import time

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

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

    return wrap

from fractions import Fraction

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

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


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

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

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

    # N = 1000
    # for _ in range(1000):
    #     A = []
    #     # A = ['7.8', '7.36', '1.79', '7.83', '1.89', '3.16', '4.40', '7.42', '5.2', '4.98', '1.15', '5.66', '5.49', '6.51', '3.50', '1.96', '5.76', '1.32', '10.59', '4.58', '2.52', '3.32', '10.69', '7.97', '2.74', '7.17', '1.76', '5.33', '4.77', '10.20', '2.36', '5.60', '3.0', '5.44', '9.21', '9.52', '5.29', '6.28', '3.46', '10.58', '7.79', '1.50', '6.56', '7.56', '6.13', '10.9', '4.94', '4.49', '9.24', '4.1', '4.70', '5.56', '5.45', '2.91', '7.54', '3.79', '7.71', '5.13', '2.19', '1.76', '8.65', '8.14', '5.7', '10.50', '9.66', '4.21', '8.14', '7.59', '1.35', '8.79', '4.99', '1.63', '7.72', '7.41', '1.18', '1.13', '10.63', '3.68', '4.20', '9.71', '1.89', '7.8', '8.56', '10.30', '1.13', '5.90', '7.79', '4.18', '7.14', '8.80', '4.93', '10.60', '2.58', '3.75', '10.74', '6.24', '2.77', '5.88', '1.4', '6.4']
    #     for _ in range(N):
    #         b = str(random.randint(1, 1000)) + '.' + str(random.randint(0, 10**7))
    #         A.append(b)

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



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
from decimal import Decimal

number_set = list()
i = 1
u = 0

a = int(input())
while i <= a:
    number_set.append(Decimal(input()))
    i += 1


for pair in itertools.combinations(number_set, 2):
    if (pair[0] * pair[1])-int((pair[0] * pair[1])) == 0:
        u += 1

print(u)

Submission status: Time Limit Exceeded

Solution code:
import pprint
N=int(input())
l2=[]
bit2=50
bit5=22
#table=[[0 for _ in range(20)] for _ in range(15)]
#table=[[0 for _ in range(45)] for _ in range(20)]
table=[[0 for _ in range(bit2)] for _ in range(bit5)]
from decimal import *
getcontext().prec=20
for i in range(N):
    pf={}
    n=float(input())
    #print(n)
    n=n*pow(10,9)
    count2=0
    count5=0
    n=Decimal(n)
    #print(n,kake)
    while n/2==n//2:
        n=n//2
        count2=count2+1
    while n/5==n//5:
        n=n//5
        count5=count5+1
    table[count5][count2]=table[count5][count2]+1
    l2.append([count2,count5])
#pprint.pprint(table)
#print(l2)
ans=0
for i in range(bit5):
    for j in range(bit2):
        num=table[i][j]
        min2=max(0,18-j)
        min5=max(0,18-i)
        cnt=0
        if num>0:
            #print(min2,min5,i,j,num)
            for k in range(min5,bit5):
                for l in range(min2,bit2):
                    cnt=cnt+table[k][l]
            if (min2<=j)and(min5<=i):
                cnt=cnt-1
            ans=ans+num*cnt
            #print(ans)
print(ans//2)