alexjercan/bugnet huggingface dataset:
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = sorted(map(int, input().split()))

cnt = [0] * (a[-1] + 1)
for i in a:
    cnt[i] += 1
for i in set(a):
    if cnt[i] >= 1:
        for j in range(i * 2, a[-1] + 1, i):
            cnt[j] = 0
print(cnt.count(1))


Error: TLE

Fixed submission:

n = int(input())
a = sorted(map(int, input().split()))

cnt = [0] * (max(a) + 1)
for i in a:
    cnt[i] += 1
for i in set(a):
    if cnt[i] >= 1:
        for j in range(i * 2, max(a) + 1, i):
            cnt[j] = 0
print(cnt.count(1))
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)

flags = [True] * (a[-1] + 1)

for e in a:
    for mul in range(2, a[-1] // e + 1):
        flags[e * mul] = False

print(sum([flags[a[i]] and c[a[i]] == 1 for i in range(n)]))


Error: TLE

Fixed submission:

from collections import Counter


n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
a = set(a)

cnt = 0
while a:
    min_val = min(a)
    a.remove(min_val)

    if c[min_val] == 1:
        cnt += 1

    if not a:
        break

    max_val = max(a)

    del_a = set()
    mul = 2
    while True:
        mul_val = min_val * mul

        if mul_val > max_val:
            break

        if mul_val in a:
            del_a.add(min_val * mul)

        mul += 1

    a -= del_a

print(cnt)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
m = max(a)
count = [0 for _ in range(m + 1)]
ans = 0

for i in a:
    if count[i] != 0:
        count[i] = 1
        continue
    for j in range(2 * i, m + 1, i):
        count[j] = 1
    count[i] = 2

for i in a:
    if count[i] != 1:
        ans += 1

print(ans)


Error: TLE

Fixed submission:

# coding:utf-8
n = int(input())
a = list(map(int, input().split()))
count = [0 for _ in range(max(a) + 1)]
ans = 0

for i in a:
    if count[i] != 0:
        count[i] = 1
        continue
    for j in range(2 * i, max(a) + 1, i):
        count[j] = 1
    count[i] = 2

for i in a:
    if count[i] != 1:
        ans += 1

print(ans)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
remain = [0 for i in range(max(a) + 1)]
for ai in a:
    remain[ai] += 1
res = 0
max_a = max(a)
for i in range(1, max_a + 1):
    if remain[i] == 1:
        res += 1
    if remain[i]:
        for j in range(i * 2, max_a + 1, i):
            remain[j] = 0
print(res)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
remain = [0 for i in range(max(a) + 1)]
for ai in a:
    remain[ai] += 1
res = 0
for i in range(1, max(a) + 1):
    if remain[i] == 1:
        res += 1
    if remain[i]:
        for j in range(i * 2, max(a) + 1, i):
            remain[j] = 0
print(res)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = False
b = [False] * 1000010
for i in range(n - 1):
    if a[i] == a[i + 1]:
        if b[a[i]]:
            continue
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

ans = 0
for i in range(n):
    if not b[a[i]]:
        ans += 1
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

print(ans)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = False
b = [False] * 1000010
for i in range(n - 1):
    if a[i] == a[i + 1]:
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

ans = 0
for i in range(n):
    if not b[a[i]]:
        ans += 1
        for j in range(a[i], 1000010, a[i]):
            b[j] = True

print(ans)
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

import numpy as np
from collections import Counter


len_arr = int(input())
arr = list(map(int, input().split(" ")))
counter = Counter(arr)
x_max = max(counter.keys())

dp = np.empty(x_max + 1, dtype=np.bool_)
dp[:] = True

ans = 0

for x, count in sorted(counter.items()):
    multi = [x * y for y in range(1, x_max // x + 1)]
    if count == 1 and dp[x]:
        ans += 1
    dp[multi] = False

print(ans)


Error: 0

Fixed submission:

from collections import Counter
import sympy


len_arr = int(input())
arr = list(map(int, input().split()))
counter = Counter(arr)
st = set(arr)

ans = 0
for value, count in counter.items():
    if count > 1:
        continue
    divs = set(sympy.divisors(value))
    if len(divs & st) == 1:
        ans += 1

print(ans)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter


n = int(input())
A = list(map(int, input().split()))

ok = [False] * (10**6 + 1)
for a in A:
    ok[a] = True

for i in range(10**6 + 1):
    if ok[i]:
        j = 2
        while i * j <= 10**6:
            ok[i * j] = False
            j += 1

for a, cnt in Counter(A).items():
    if cnt >= 2:
        ok[a] = False

print(sum(ok))


Error: TLE

Fixed submission:

n = int(input())
A = sorted(map(int, input().split()))

B = [1] * n
for i in range(n):
    if B[i] == 0:
        continue
    a = A[i]
    for j in range(i + 1, n):
        if A[j] % a == 0:
            B[j] = 0

for i in range(n - 1):
    if B[i] == 1:
        if A[i] == A[i + 1]:
            B[i] = 0

print(sum(B))
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_sort = sorted(set(A))

bool_list = [True] * (10**6 + 1)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a] = False

for a in A_sort:
    for i in range(2 * a, 10**6 + 1, a):
        bool_list[i] = False

print(sum([1 for a in A_sort if bool_list[a]]))


Error: TLE

Fixed submission:

from collections import Counter

N = int(input())
A = list(map(int, input().split()))

A_sort = sorted(set(A))
A_counter = Counter(A)
# print(A_sort)

res = 0
# res_list = []
for i in range(len(A_sort)):
    # print(A_sort[i], A_sort_tmp)
    if A_counter[A_sort[i]] >= 2:
        continue

    A_sort_tmp = A_sort[:i]
    for j in range(len(A_sort_tmp)):
        if A_sort[i] % A_sort_tmp[j] == 0:
            break
    else:
        res += 1
        # res_list.append(i + 1)

print(res)
# print(res_list)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
AS = [int(x) for x in input().split()]

AS.sort(reverse=True)
MAX_AS = AS[0]
table = [0] * (MAX_AS + 1)  # 1..max(AS)

alreadyVisited = {}
for i in range(N):
    x = dx = AS[i]
    if alreadyVisited.get(x, False):
        table[x] = 0
        continue
    alreadyVisited[x] = True

    table[x] = 1
    while True:
        x += dx
        if x > MAX_AS:
            break
        table[x] = 0

print(sum(table))


Error: TLE

Fixed submission:

N = int(input())
AS = [int(x) for x in input().split()]

ok = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if AS[i] % AS[j] == 0:
            break
    else:
        ok.append(i)

print(len(ok))
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

n = int(input())
a = list(map(int, input().split()))

# new = [key for key, val in Counter(a).most_common() if val == 1]
prime = [1] * 1000010

for i in set(a):
    # if prime[i]:
    for j in range(i + i, 1000001, i):
        prime[j] = 0

c = Counter(a)
ans = 0
for i in a:
    if prime[i] and c[i] == 1:
        ans += 1
print(ans)


Error: 0

Fixed submission:

from collections import Counter

n = int(input())
a = list(map(int, input().split()))

new = [key for key, val in Counter(a).most_common() if val == 1]
dp = [0] * 100010

for i in new:
    for j in range(0, 100000, i):
        dp[j] += 1

ans = 0
for i in new:
    if dp[i] == 1:
        ans += 1
print(ans)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))


def solve2(N, A):
    A.sort()
    amax = A[-1]
    dp = [True] * (amax + 1)
    cnt = [0] * (amax + 1)

    for a in A:
        cnt[a] += 1

    for i in range(amax):
        x = i + 1
        if cnt[x] > 1:
            dp[x] = False

        if cnt[x] > 0:
            y = x * 2
            while y <= amax:
                dp[y] = False
                y += x

    ansval = [x for x in A if dp[x]]

    # print(ansval)
    ans = len(ansval)

    return ans


def solve1(N, A):
    ans = 0
    for i in range(N):
        is_ans = True
        for j in range(N):
            if i != j:
                if A[i] % A[j] == 0:
                    is_ans = False
                    break

        if is_ans:
            ans += 1

    return ans


print(solve2(N, A))


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))


count = 0
for i in range(N):
    is_ans = True
    for j in range(N):
        if i != j:
            if A[i] % A[j] == 0:
                is_ans = False
                break

    if is_ans:
        count += 1

print(count)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

N = int(input())
A = [int(Ai) for Ai in input().split()]

counter = Counter(A)

dp = [1] * (max(A) + 1)
for Ai in A:
    for j in range(Ai * 2, len(dp), Ai):
        dp[j] = 0

print(sum([dp[Ai] == 1 and counter[Ai] == 1 for Ai in A]))


Error: TLE

Fixed submission:

N = int(input())
A = [int(Ai) for Ai in input().split()]

count = 0
for i, Ai in enumerate(A):
    found = False
    for j, Aj in enumerate(A):
        if i != j and Ai % Aj == 0:
            found = True
            break
    if not found:
        count += 1

print(count)
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
a = list(map(int, input().split()))
m = max(a)
y = [0] * (m + 1)
for i in a:
    x = i
    while x <= m:
        y[x] += 1
        x += i
ans = 0
for j in a:
    if y[j] == 1:
        ans += 1

print(ans)


Error: 0

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
a.sort()
ans = 0
if len(a) == 1:
    print(0)
else:
    for _ in range(n):
        m = a.pop()
        ind = True
        for i in a:
            if m % i == 0:
                ind = False
                break
        if ind:
            ans += 1
    print(ans)
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

from numba import njit


@njit(fastmath=True)
def fact(x):
    i = 1
    while i * i <= x:
        if x % i == 0:
            yield i
            yield x // i
        i += 1


def main():
    n = int(input())
    a = tuple(map(int, input().split()))

    c = [0] * (max(a) + 1)

    for e in a:
        c[e] += 1

    ans = n
    for e in a:
        c[e] -= 1
        for fct in fact(e):
            if c[fct]:
                ans -= 1
                break

        c[e] += 1

    print(ans)


if __name__ == "__main__":
    main()


Error: ModuleNotFoundError: No module named 'numba'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02642/Python/s936960783.py", line 1, in <module>
    from numba import njit
ModuleNotFoundError: No module named 'numba'


Fixed submission:

from numba import njit


@njit(cache=True)
def fact(x):
    i = 1
    while i * i <= x:
        if x % i == 0:
            yield i
            yield x // i
        i += 1


def main():
    n = int(input())
    a = tuple(map(int, input().split()))

    c = [0] * (max(a) + 1)

    for e in a:
        c[e] += 1

    ans = n
    for e in a:
        c[e] -= 1
        for fct in fact(e):
            if c[fct]:
                ans -= 1
                break

        c[e] += 1

    print(ans)


if __name__ == "__main__":
    main()
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-
n = int(input())
a = sorted(list(map(int, input().split())))

# 探索範囲は数列aの最大値まで
max_a = a[-1]
b = [0] * (max_a + 1)
ans = set()
for i in a:
    if b[i] == 1:
        if i in ans:
            ans.remove(i)
        continue
    # 探索範囲内のiの倍数をチェック
    for j in range(i, max_a + 1, i):
        b[j] = 1
    ans.add(i)

print(len(ans))


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n):
    is_divisible = False
    for j in range(n):
        divisible_num = []
        if a[i] % a[j] == 0 and i != j:
            divisible_num.append(a[j])
            is_divisible = True
        if len(divisible_num) >= 1:
            continue
    if is_divisible:
        continue
    else:
        count += 1

print(count)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
A = [int(x) for x in input().split()]
A.sort()
lim = A[-1]
se = [True for i in range(lim + 1)]
ans = 0
for i, a in enumerate(A):
    if se[a]:
        if not ((i != n - 1 and A[i + 1] == a) or (i != 0 and A[i - 1] == a)):
            ans += 1
        tmp = a
        while not tmp > lim:
            se[tmp] = False
            tmp += a
print(ans)


Error: TLE

Fixed submission:

n = int(input())
A = [int(x) for x in input().split()]
A.sort()
ans = 0
for i, a in enumerate(A):
    if i != n - 1 and A[i + 1] == a:
        continue
    do_count = True
    for j in range(i):
        b = A[j]
        if a % b == 0:
            do_count = False
            break
    if do_count:
        ans += 1
print(ans)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
a = sorted(list(map(int, input().split())))

ans = 0
dp = [0] * (a[-1] + 1)

for i in range(n):
    tmp = a[i]
    while tmp <= a[-1]:
        dp[tmp] += 1
        tmp += a[i]

for i in a:
    if dp[i] == 1:
        ans += 1

print(ans)


Error: TLE

Fixed submission:

n = int(input())
a = list(map(int, input().split()))

left = 0
right = n - 1
ans = 0

for i in range(n):
    left = 0
    right = n - 1
    while left <= right:
        if i == left == right:
            left, right = left + 1, right - 1
            continue

        elif i == left:
            if a[i] % a[right] == 0:
                break

        elif i == right:
            if a[i] % a[left] == 0:
                break

        else:
            if a[i] % a[left] == 0 or a[i] % a[right] == 0:
                break

        left, right = left + 1, right - 1

    if left > right:
        ans += 1

print(ans)
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

n = int(input())
alist = [int(v) for v in input().split()]
dup_set = {k for k, v in Counter(alist).items() if v >= 2}
alist = sorted(set(alist))
adict = {a: False for a in alist}
a_max = alist[-1]
max_ind = -1

count = 0
if 1 in adict:
    count = 0 if 1 in dup_set else 1
else:
    for a, f in adict.items():
        if f:
            continue
        if a not in dup_set:
            count += 1
        for k in range(a, a_max + 1, a):
            if k in adict:
                adict[k] = True
                if k == a_max:
                    max_ind -= 1
                    if abs(max_ind) <= len(alist):
                        a_max = alist[max_ind]

print(count)


Error: 0

Fixed submission:

from collections import Counter

n = int(input())
alist = [int(v) for v in input().split()]
dup_set = {k for k, v in Counter(alist).items() if v >= 2}
alist = sorted(set(alist))
adict = {a: False for a in alist}
a_max = alist[-1]
max_ind = -1

count = 0
if 1 in adict:
    count = 0 if 1 in dup_set else 1
else:
    for a, f in adict.items():
        if f:
            continue
        if a not in dup_set:
            count += 1
        for k in range(a, a_max + 1, a):
            if k in adict:
                adict[k] = True
                if k == a_max:
                    max_ind -= 1
                    a_max = alist[max_ind]

print(count)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

N = int(input())
A = list(map(int, input().split()))
A.sort()
MA = max(A)
dp = [True for _ in range(MA + 1)]
flag = [False for _ in range(MA + 1)]

for i in range(N):
    a = A[i]
    if not flag[a]:
        flag[a] = True
        t = a * 2
        while t <= MA:
            dp[t] = False
            t += a
    elif flag[a] == 1:
        dp[a] = False
res = 0
for a in A:
    if dp[a]:
        res += 1
print(res)


Error: TLE

Fixed submission:

N = int(input())
A = list(map(int, input().split()))
A.sort()
res = 0
while A:
    if len(A) == 1:
        res += 1
    else:
        if A[0] != A[1]:
            res += 1
    t = A[0]
    NA = []
    for a in A:
        if a % t != 0:
            NA.append(a)
    A = NA[:]
print(res)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
aL = sorted(list(map(int, input().split(" "))))
# aL = sorted(list(set(aLP)))

dp = [False for _ in range(1000001)]

d = {}
for a in aL:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

ans = 0
for a in aL:
    if dp[a]:
        continue
    if d[a] > 1:
        c = 1
        while a * c <= 1000000:
            dp[a * c] = True
            c += 1
        continue
    ans += 1

    c = 1
    while a * c <= 1000000:
        dp[a * c] = True
        c += 1

print(ans)


Error: TLE

Fixed submission:

n = int(input())
aL = sorted(list(map(int, input().split(" "))))
# aL = sorted(list(set(aLP)))

dp = [False for _ in range(1000001)]

ans = 0
for a in aL:
    if dp[a] or aL.count(a) > 1:
        continue
    ans += 1

    c = 1
    while a * c <= 1000000:
        dp[a * c] = True
        c += 1

print(ans)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import Counter

n = int(input())
data = list(map(int, input().split()))

max_ = 10**6 + 1
b = [True] * (max_ + 1)
data.sort()
c = Counter(data)

ans = 0
for d in data:
    if b[d]:
        for j in range(d, max_, d):
            b[j] = False
        # 複数存在
        if c[d] > 1:
            continue
        else:
            ans += 1

print(ans)


Error: TLE

Fixed submission:

n = int(input())
data = list(map(int, input().split()))

ans_list = []
for i in range(n):
    f = True
    for j in range(n):
        if i == j:
            continue

        if data[i] % data[j] == 0:
            f = False
            break

    if f:
        ans_list.append(data[i])

print(len(ans_list))
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
a = list(map(int, input().split()))
a.sort()

cnt = [0] * (a[-1] + 1)
for i in range(n):
    cnt[a[i]] += 1

ans = 0
for i in range(1, a[-1] + 1):
    if cnt[i] > 0:
        if cnt[i] == 1:
            ans += 1
        for j in range(2, a[-1] + 1):
            na = i * j
            if na <= a[-1]:
                cnt[na] = 0
            else:
                break

print(ans)


Error: 0

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
a.sort()

ans = 0
for i in range(n):
    cnt = 0
    if i > 0 and a[i] == a[i - 1]:
        continue
    for j in range(i):
        if a[j] > a[i] // 2:
            break
        if a[i] % a[j] == 0:
            cnt += 1
            break
    if cnt == 0:
        if i != 0:
            # print(i, a[i])
            ans += 1
        elif a[0] != a[1]:
            # i == 0
            ans += 1

print(ans)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

n = int(input())
A = list(map(int, input().split()))
A.sort()

dp = [False] * (A[-1] + 1)
for a in A:
    dp[a] = True

for idx, a in enumerate(A):
    if A[idx] == A[idx - 1]:
        if idx == 0:
            None
        else:
            dp[a] = False
    for j in range(2, A[-1] // a + 1):
        dp[a * j] = False

count = 0
for d in dp:
    if d:
        count += 1
print(count)


Error: TLE

Fixed submission:

n = int(input())
A = list(map(int, input().split()))

A.sort()
count = 0
for i in range(n - 1):
    if A[i] % A[i + 1] == 0:
        count += 1
        continue
    for j in range(i):
        if A[i] % A[j] == 0:
            count += 1
            break
i = n - 1
for j in range(i):
    if A[i] % A[j] == 0:
        count += 1
        break
print(n - count)
Problem p02642 (Python) — buggy submission, verdict: Time Limit Exceeded

#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))

A.sort()
A_max = A[-1]
table = [0] * (A_max + 1)

for x in A:
    table[x] += 1
    for y in range(x * 2, A_max + 1, x):
        table[y] += 1

result = sum([1 for x in A if table[x] == 1])
print(result)


Error: TLE

Fixed submission:

#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
A.sort()

count = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue

        if A[i] % A[j] == 0:
            break

    else:
        count += 1

print(count)
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

from collections import Counter

N = int(input())
a = sorted(list(map(int, input().split())))

M = 10**6

table = [1] * (M + 1)

B = Counter(a)
Key = list(B.keys())

count = 0
for x in Key:
    if B[x] == 1 and table[x] == 1:
        count += 1

    for i in range(M):
        if i * x > M:
            break
        else:
            table[i * x] = 0

print(count)


Error: 0

Fixed submission:

from collections import Counter

N = int(input())
a = sorted(list(map(int, input().split())))

M = 10**6 + 1

table = [1] * M

B = Counter(a)
Key = list(B.keys())

count = 0
for x in Key:
    if B[x] == 1 and table[x] == 1:
        count += 1

    for i in range(M):
        if i * x > M:
            break
        else:
            table[i * x] = 0

print(count)
Problem p02642 (Python) — buggy submission, verdict: Runtime Error

n = int(input())
A = list(map(int, input().split()))

A.sort()
A.append(-1)

x = A[0]
if x != 1:
    flag = True
    for a in A:
        if a % x != 0:
            flag = False
    if flag:
        print(0)
        exit()

used = [False] * A[-2]
ans = 0
for idx, a in enumerate(A[:-1]):
    if used[a - 1]:
        continue
    if a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)


Error: IndexError: list index out of range
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02642/Python/s321495509.py", line 21, in <module>
    if a != A[idx + 1]:
IndexError: list index out of range


Fixed submission:

n = int(input())
A = list(map(int, input().split()))

A.sort()
A.append(-1)

x = A[0]
flag = True
for a in A:
    if a % x != 0:
        flag = False
if flag:
    print(0)
    exit()

used = [False] * A[-2]
ans = 0
for idx, a in enumerate(A):
    if used[a - 1]:
        continue
    if a != A[idx + 1]:
        ans += 1
    for j in range(a, len(used) + 1, a):
        used[j - 1] = True
print(ans)