Problem p02588 (python)

Fixed submission:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    return a[i][j]+a[arg][j] >= 0

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n = INT()
a = [[0]*19 for i in range(19)]
for i in range(n):
    A = int(float(input())*10**9+0.5)
    m2 = m5 = 0
    while A % 2 == 0:
        A //= 2
        m2 += 1
    while A % 5 == 0:
        A //= 5
        m5 += 1
    m2 = min(m2, 18)
    m5 = min(m5, 18)
    a[m2][m5] += 1

ans = 0
for i in range(19):
    for j in range(19):
        for k in range(19):
            for l in range(19):
                if i + k >= 18 and j + l >= 18:
                    if i == k and j == l:
                        ans += a[i][j] * ( a[k][l] - 1 )
                    else:
                        ans += a[i][j] * a[k][l]
ans //= 2
print(ans)

Buggy submission (verdict: Runtime Error):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    return a[i][j]+a[arg][j] >= 0

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n = INT()
a = [[0]*25 for i in range(25)]
for i in range(n):
    A = int(float(input())*10**9)
    m2 = m5 = 0
    while A % 10 == 0:
        A //= 10
        m2 += 1
        m5 += 1
    while A % 2 == 0:
        A //= 2
        m2 += 1
    while A % 5 == 0:
        A //= 5
        m5 += 1
    a[m2][m5] += 1

ans = 0
for i in range(25):
    for j in range(25):
        if a[i][j] > 0:
            for k in range(25):
                for l in range(25):
                    if i + k >= 18 and j + l >= 18:
                        if i == k and j == l:
                            ans += a[i][j] * ( a[k][l] - 1 )
                        else:
                            ans += a[i][j] * a[k][l]
ans //= 2
print(ans)

Buggy submission (verdict: Runtime Error):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    return a[i][j]+a[arg][j] >= 0

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n = INT()
a = [[0]*20 for i in range(20)]
for i in range(n):
    A = int(float(input())*10**9)
    m2 = m5 = 0
    while A % 10 == 0:
        A //= 10
        m2 += 1
        m5 += 1
    while A % 2 == 0:
        A //= 2
        m2 += 1
    while A % 5 == 0:
        A //= 5
        m5 += 1
    a[m2][m5] += 1

ans = 0
for i in range(20):
    for j in range(20):
        if a[i][j] > 0:
            for k in range(20):
                for l in range(20):
                    if i + k >= 18 and j + l >= 18:
                        if i == k and j == l:
                            ans += a[i][j] * ( a[k][l] - 1 )
                        else:
                            ans += a[i][j] * a[k][l]
ans //= 2
print(ans)

Buggy submission (verdict: Runtime Error):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def is_ok(arg):
    return a[i][j]+a[arg][j] >= 0

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n = INT()
a = [[0]*15 for i in range(15)]
for i in range(n):
    A = int(float(input())*10**9)
    m2 = m5 = 0
    while A % 10 == 0:
        A //= 10
        m2 += 1
        m5 += 1
    while A % 2 == 0:
        A //= 2
        m2 += 1
    while A % 5 == 0:
        A //= 5
        m5 += 1
    a[m2][m5] += 1

ans = 0
for i in range(15):
    for j in range(15):
        if a[i][j] > 0:
            for k in range(15):
                for l in range(15):
                    if i + k >= 18 and j + l >= 18:
                        if i == k and j == l:
                            ans += a[i][j] * ( a[k][l] - 1 )
                        else:
                            ans += a[i][j] * a[k][l]
ans //= 2
print(ans)