Problem p02588 (python)

Fixed submission:
def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
dp = [[0]*19 for _ in range(19)]

ans = 0
for _ in range(n):
    x = round(float(input()) * pow(10, 9))
    two = div(x, 2)
    five = div(x, 5)
    ans += dp[18 - two][18 - five]
    for i in range(two + 1):
        for j in range(five + 1):
            dp[i][j] += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = (f(arr, 2) + np.zeros([arr.shape[0],
                              arr.shape[0]], np.int64)).astype(np.int32)
arr5 = (f(arr, 5) + np.zeros([arr.shape[0],
                              arr.shape[0]], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = (f(arr, 2) + np.zeros([arr.shape[0],　arr.shape[0]], np.int64)).astype(np.int32)
arr5 = (f(arr, 5) + np.zeros([arr.shape[0],　arr.shape[0]], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np
from functools import lru_cache


@lru_cache(maxsize=None)
def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = (f(arr, 2) + np.zeros([arr.shape[0],　arr.shape[0]], np.int64)).astype(np.int32)
arr5 = (f(arr, 5) + np.zeros([arr.shape[0],　arr.shape[0]], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np
from functools import lru_cache


@lru_cache(maxsize=None)
def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())

arr2 = []
arr5 = []
for _ in range(n):
    x = round(float(input()) * 10**9)
    arr2.append(div(x, 2))
    arr5.append(div(x, 5))

arr2 = np.array(arr2)
arr5 = np.array(arr5)
shape = arr2.shape[0]

arr2 = (arr2 + np.zeros([shape, shape], np.int64)).astype(np.int32)
arr5 = (arr5 + np.zeros([shape, shape], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())

arr2 = []
arr5 = []
for _ in range(n):
    x = round(float(input()) * 10**9)
    arr2.append(div(x, 2))
    arr5.append(div(x, 5))

arr2 = np.array(arr2)
arr5 = np.array(arr5)
shape = arr2.shape[0]

arr2 = (arr2 + np.zeros([shape, shape], np.int64)).astype(np.int32)
arr5 = (arr5 + np.zeros([shape, shape], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    if d == 2:
        return format(n, "b")[::-1].find("1")
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())

arr2 = []
arr5 = []
for _ in range(n):
    x = round(float(input()) * 10**9)
    arr2.append(div(x, 2))
    arr5.append(div(x, 5))

arr2 = np.array(arr2)
arr5 = np.array(arr5)
shape = arr2.shape[0]

arr2 = (arr2 + np.zeros([shape, shape], np.int64)).astype(np.int32)
arr5 = (arr5 + np.zeros([shape, shape], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    if d == 2:
        return format(n, "b")[::-1].find("1")
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())

arr2 = []
arr5 = []
for _ in range(n):
    x = round(float(input()) * 10**9)
    arr2.append(div(x, 2))
    arr5.append(div(x, 5))

shape = arr2.shape[0]

arr2 = (np.array(arr2) + np.zeros([shape, shape], np.int64)).astype(np.int32)
arr5 = (np.array(arr5) + np.zeros([shape, shape], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    if d == 2:
        return format(n, "b")[::-1].find("1")
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())

arr2 = []
arr5 = []
for _ in range(n):
    x = round(float(input()) * 10**9)
    arr2.append(div(x, 2))
    arr5.append(div(x, 5))

arr2 = (np.array(arr2) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)).astype(np.int32)
arr5 = (np.array(arr5) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    if d == 2:
        return format(n, "b")[::-1].find("1")
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = (f(arr, 2) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)).astype(np.int32)
arr5 = (f(arr, 5) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np


def div(n, d):
    if d == 2:
        return format(n, "b")[::-1].find("1")
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = f(arr, 2) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)
arr5 = f(arr, 5) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit, i4, i8


@njit(i8(i8, i4), cache=True)
def div(n, d):
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = f(arr, 2) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)
arr5 = f(arr, 5) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit, i4, i8


@njit(i8(i8, i4), cache=True)
def div(n, d):
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = f(arr, 2) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)
arr5 = f(arr, 5) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)

arr2 = np.tril(arr2 + arr2.T) - np.triu(arr2 + arr2.T)
arr5 = np.tril(arr5 + arr5.T) - np.triu(arr5 + arr5.T)

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit, i4, i8


@njit(i8(i8, i4), cache=True)
def div(n, d):
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


@njit(i8(i8[:, :], i8), cache=True)
def solve(arr, length):
    ans = 0
    for i in range(length):
        for j in range(i + 1, length):
            a, b, c, d = arr[0][i], arr[1][i], arr[0][j], arr[1][j]
            if a + c >= 18 and b + d >= 18:
                ans += 1
    return ans


n = int(input())
arr = np.array([float(input()) for _ in range(n)], np.float64)
arr = np.rint(arr * 10**9).astype(np.int64)

f = np.vectorize(div)
arr2 = f(arr, 2) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)
arr5 = f(arr, 5) + np.zeros([arr.shape[0], arr.shape[0]], np.int64)

arr2 = np.tril(arr2 + arr2.T) - np.triu(arr2 + arr2.T)
arr5 = np.tril(arr5 + arr5.T) - np.triu(arr5 + arr5.T)

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

Buggy submission (verdict: Runtime Error):
from decimal import Decimal
from numba import njit, i4, i8


@njit(i8(i8, i4), cache=True)
def div(n, d):
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


@njit(cache=True)
def solve(arr):
    ans = 0
    for i in range(len(arr)):
        for j in range(i + 1, len(arr)):
            (a, b), (c, d) = arr[i], arr[j]
            if a + c >= 18 and b + d >= 18:
                ans += 1
    return ans


n = int(input())
arr = [int(Decimal(input()) * 10**9) for _ in range(n)]
arr = [(div(x, 2), div(x, 5)) for x in arr]

print(solve(ans))

Buggy submission (verdict: Runtime Error):
from numba import njit


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

ans = 0
for i in range(len(arr)):
    for j in range(i + 1, len(arr)):
        (a, b), (c, d) = arr[i], arr[j]
        if a + c >= 18 and b + d >= 18:
            ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
cand = list(set([2**x * 5**y for x in range(18)
                 for y in range(8) if 2**x * 5**y <= 200000]))
cand.sort()


def f(n):
    cnt = 0
    while True:
        x = n * cand[cnt]
        if x.is_integer():
            return cand[cnt]
        else:
            cnt += 1


def div(n, bl=True):
    if bl and not n.is_integer():
        return (0, 0)
    else:
        n = int(n)
        two = format(n, 'b')[::-1].find('1')
        n = n >> two
        cnt = 0
        while n % 5 == 0:
            n //= 5
            cnt += 1
        return (two, cnt)


n = int(input())
arr = [float(input()) for _ in range(n)]

x = [div(x) for x in arr]
y = [div(x, False) for x in [f(x) for x in arr]]
z = [div(x * 2**y1 * 5**z, False) for x, (y1, z) in zip(arr, y)]


ans = 0
for i in range(len(y)):
    for j in range(i + 1, len(y)):
        (a, b), (c, d) = y[i], y[j]
        if a == 0 and b == 0 and c == 0 and d == 0:
            ans += 1
        elif a + c <= z[i][0] + z[j][0] and b + d <= z[i][1] + z[j][1]:
            ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math

cand = list(set([2**x * 5**y for x in range(18) for y in range(8) if 2**x * 5**y <= 200000]))
cand.sort()


def f(n):
    cnt = 0
    while True:
        x = n * cand[cnt]
        if x.is_integer():
            return cand[cnt]
        else:
            cnt += 1


def div(n, bl=True):
    if bl and not n.is_integer():
        return (0, 0)
    else:
        n = int(n)
        two = format(n, 'b')[::-1].find('1')
        n = n >> two
        cnt = 0
        while n % 5 == 0:
            n //= 5
            cnt += 1
        return (two, cnt)


n = int(input())
arr = [float(input()) for _ in range(n)]
arr = [x for x in arr if min(x - int(x), math.ceil(x) - x) >= 0.000005 or x == int(x)]

x = [div(x) for x in arr]
y = [div(x, False) for x in [f(x) for x in arr]]
z = [div(x * 2**y1 * 5**z, False) for x, (y1, z) in zip(arr, y)]


ans = 0
for i in range(len(y)):
    for j in range(i + 1, len(y)):
        (a, b), (c, d) = y[i], y[j]
        if a == 0 and b == 0 and c == 0 and d == 0:
            ans += 1
        elif a + c <= z[i][0] + z[j][0] and b + d <= z[i][1] + z[j][1]:
            ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
cand = list(set([2**x * 5**y for x in range(18) for y in range(8) if 2**x * 5**y <= 200000]))
cand.sort()


def f(n):
    cnt = 0
    while True:
        x = n * cand[cnt]
        if x.is_integer():
            return cand[cnt]
        else:
            cnt += 1


def div(n, bl=True):
    if bl and not n.is_integer():
        return (0, 0)
    else:
        n = int(n)
        two = format(n, 'b')[::-1].find('1')
        n = n >> two
        cnt = 0
        while n % 5 == 0:
            n //= 5
            cnt += 1
        return (two, cnt)


n = int(input())
arr = [float(input()) for _ in range(n)]
arr = [x for x in arr if min(x - int(x), math.ceil(x) - x) >= 0.000005 or x == int(x)]

x = [div(x) for x in arr]
y = [div(x, False) for x in [f(x) for x in arr]]
z = [div(x * 2**y1 * 5**z, False) for x, (y1, z) in zip(arr, y)]


ans = 0
for i in range(len(y)):
    for j in range(i + 1, len(y)):
        (a, b), (c, d) = y[i], y[j]
        if a == 0 and b == 0 and c == 0 and d == 0:
            ans += 1
        elif a + c <= z[i][0] + z[j][0] and b + d <= z[i][1] + z[j][1]:
            ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
import math


def solve(a, b):
    x = a * b
    return int(x) == math.ceil(x)


n = int(input())
arr = [Decimal(input()) for _ in range(n)]


ans = []
for x, y in combinations(arr, 2):
    ans.append(solve(x, y))

print(sum(ans))