Problem p02588 (python)

Fixed submission:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    n = int(input())
    C = Counter()
    for _ in range(n):
        S = input()
        if '.' in S:
            a, b = S.split('.')
            a = int(a + b + '0' * (9 - len(b)))
        else:
            a = int(S + '0' * 9)
        two = five = 0
        while a % 2 == 0:
            two += 1
            a //= 2
        while a % 5 == 0:
            five += 1
            a //= 5
        C[two, five] += 1

    ans = 0
    for key0, val0 in C.items():
        i0, j0 = key0
        for key1, val1 in C.items():
            i1, j1 = key1
            if i0 + i1 >= 18 and j0 + j1 >= 18:
                if key0 == key1:
                    ans += val0 * (val0 - 1) // 2
                elif key0 < key1:
                    ans += val0 * val1
    print(ans)
resolve()

Buggy submission (verdict: Runtime Error):
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [[0] * 18 for _ in range(26)]
    ans = 0
    for _ in range(n):
        S = input()
        if '.' in S:
            a, b = S.split('.')
            a = int(a + b + '0' * (9 - len(b)))
        else:
            a = int(S + '0' * 9)
        two = five = 0
        while a % 2 == 0:
            two += 1
            a //= 2
        while a % 5 == 0:
            five += 1
            a //= 5
        for i in range(26):
            for j in range(18):
                if i + two >= 18 and j + five >= 18:
                    ans += counter[i][j]
        counter[two][five] += 1
    print(ans)
resolve()

Buggy submission (verdict: Runtime Error):
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [[0] * 16 for _ in range(24)]
    ans = 0
    for _ in range(n):
        S = input()
        if '.' in S:
            a, b = S.split('.')
            a = int(a + b + '0' * (9 - len(b)))
        else:
            a = int(S + '0' * 9)
        two = five = 0
        while a % 2 == 0:
            two += 1
            a //= 2
        while a % 5 == 0:
            five += 1
            a //= 5
        for i in range(24):
            for j in range(16):
                if i + two >= 18 and j + five >= 18:
                    ans += counter[i][j]
        counter[two][five] += 1
    print(ans)
resolve()

Buggy submission (verdict: Runtime Error):
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [[0] * 16 for _ in range(24)] # -9 ~ 13, -9 ~ 5
    ans = 0
    for _ in range(n):
        S = input()
        if '.' in S:
            a, b = S.split('.')
            two = five = -len(b)
            a = int(a + b)
        else:
            two = five = 0
            a = int(S)
        while a % 2 == 0:
            two += 1
            a //= 2
        while a % 5 == 0:
            five += 1
            a //= 5
        for i in range(-9, 14):
            for j in range(-9, 6):
                if two + i >= 0 and five + j >= 0:
                    ans += counter[i][j]
        counter[two][five] += 1
    print(ans)
resolve()